動(dòng)態(tài)規(guī)劃的方程大家都知道,就是 f[i,j]=min{f[i-1,j-1],f[i-1,j],f[i,j-1],f[i,j+1]}+a[i,j] 但是很多人會(huì)懷疑這道題的后效性而放棄動(dòng)規(guī)做法。 本來(lái)我還想做Dijkstra,后來(lái)變了沒(méi)二十行pascal就告訴我數(shù)組越界了……(dist:array[1..1000*1001 div 2]...) 無(wú)奈之余看了xj_kidb1的題解,剛開(kāi)始還覺(jué)得有問(wèn)題,后來(lái)豁然開(kāi)朗…… 反復(fù)動(dòng)規(guī)。上山容易下山難,我們可以從上往下走,最后輸出f[n][1]。 xj_kidb1的一個(gè)技巧很重要,每次令f[i][0]=f[i][i],f[i][i+1]=f[i][1](xj_kidb1的題解還寫(xiě)錯(cuò)了)
標(biāo)簽: 動(dòng)態(tài)規(guī)劃 方程 家
上傳時(shí)間: 2014-07-16
上傳用戶:libinxny
Euler函數(shù): m = p1^r1 * p2^r2 * …… * pn^rn ai >= 1 , 1 <= i <= n Euler函數(shù): 定義:phi(m) 表示小于等于m并且與m互質(zhì)的正整數(shù)的個(gè)數(shù)。 phi(m) = p1^(r1-1)*(p1-1) * p2^(r2-1)*(p2-1) * …… * pn^(rn-1)*(pn-1) = m*(1 - 1/p1)*(1 - 1/p2)*……*(1 - 1/pn) = p1^(r1-1)*p2^(r2-1)* …… * pn^(rn-1)*phi(p1*p2*……*pn) 定理:若(a , m) = 1 則有 a^phi(m) = 1 (mod m) 即a^phi(m) - 1 整出m 在實(shí)際代碼中可以用類似素?cái)?shù)篩法求出 for (i = 1 i < MAXN i++) phi[i] = i for (i = 2 i < MAXN i++) if (phi[i] == i) { for (j = i j < MAXN j += i) { phi[j] /= i phi[j] *= i - 1 } } 容斥原理:定義phi(p) 為比p小的與p互素的數(shù)的個(gè)數(shù) 設(shè)n的素因子有p1, p2, p3, … pk 包含p1, p2…的個(gè)數(shù)為n/p1, n/p2… 包含p1*p2, p2*p3…的個(gè)數(shù)為n/(p1*p2)… phi(n) = n - sigm_[i = 1](n/pi) + sigm_[i!=j](n/(pi*pj)) - …… +- n/(p1*p2……pk) = n*(1 - 1/p1)*(1 - 1/p2)*……*(1 - 1/pk)
標(biāo)簽: Euler lt phi 函數(shù)
上傳時(shí)間: 2014-01-10
上傳用戶:wkchong
//Euler 函數(shù)前n項(xiàng)和 /* phi(n) 為n的Euler原函數(shù) if( (n/p) % i == 0 ) phi(n)=phi(n/p)*i else phi(n)=phi(n/p)*(i-1) 對(duì)于約數(shù):divnum 如果i|pr[j] 那么 divnum[i*pr[j]]=divsum[i]/(e[i]+1)*(e[i]+2) //最小素因子次數(shù)加1 否則 divnum[i*pr[j]]=divnum[i]*divnum[pr[j]] //滿足積性函數(shù)條件 對(duì)于素因子的冪次 e[i] 如果i|pr[j] e[i*pr[j]]=e[i]+1 //最小素因子次數(shù)加1 否則 e[i*pr[j]]=1 //pr[j]為1次 對(duì)于本題: 1. 篩素?cái)?shù)的時(shí)候首先會(huì)判斷i是否是素?cái)?shù)。 根據(jù)定義,當(dāng) x 是素?cái)?shù)時(shí) phi[x] = x-1 因此這里我們可以直接寫(xiě)上 phi[i] = i-1 2. 接著我們會(huì)看prime[j]是否是i的約數(shù) 如果是,那么根據(jù)上述推導(dǎo),我們有:phi[ i * prime[j] ] = phi[i] * prime[j] 否則 phi[ i * prime[j] ] = phi[i] * (prime[j]-1) (其實(shí)這里prime[j]-1就是phi[prime[j]],利用了歐拉函數(shù)的積性) 經(jīng)過(guò)以上改良,在篩完素?cái)?shù)后,我們就計(jì)算出了phi[]的所有值。 我們求出phi[]的前綴和 */
標(biāo)簽: phi Euler else 函數(shù)
上傳時(shí)間: 2016-12-31
上傳用戶:gyq
遙控解碼通過(guò)電腦串口顯示 /* 晶振:11.0569MHz */ #include <REGX52.h> #define uchar unsigned char uchar data IRcode[4] //定義一個(gè)4字節(jié)的數(shù)組用來(lái)存儲(chǔ)代碼 uchar CodeTemp //編碼字節(jié)緩存變量 uchar i,j,k //延時(shí)用的循環(huán)變量 sbit IRsignal=P3^2 //HS0038接收頭OUT端直接連P3.2(INT0) /**************************延時(shí)0.9ms子程序**********************/ void Delay0_9ms(void) {uchar j,k for(j=18 j>0 j--) for(k=20 k>0 k--) } /***************************延時(shí)1ms子程序**********************/ void Delay1ms(void) {uchar i,j for(i=2 i>0 i--) for(j=230 j>0 j--) }
標(biāo)簽: uchar unsigned 11.0569 include
上傳時(shí)間: 2013-12-12
上傳用戶:Breathe0125
Instead of finding the longest common subsequence, let us try to determine the length of the LCS. Then tracking back to find the LCS. Consider a1a2…am and b1b2…bn. Case 1: am=bn. The LCS must contain am, we have to find the LCS of a1a2…am-1 and b1b2…bn-1. Case 2: am≠bn. Wehave to find the LCS of a1a2…am-1 and b1b2…bn, and a1a2…am and b b b b1b2…bn-1 Let A = a1 a2 … am and B = b1 b2 … bn Let Li j denote the length of the longest i,g g common subsequence of a1 a2 … ai and b1 b2 … bj. Li,j = Li-1,j-1 + 1 if ai=bj max{ L L } a≠b i-1,j, i,j-1 if ai≠j L0,0 = L0,j = Li,0 = 0 for 1≤i≤m, 1≤j≤n.
標(biāo)簽: the subsequence determine Instead
上傳時(shí)間: 2013-12-17
上傳用戶:evil
//初始化 initscr() //獲得屏幕尺寸 getmaxyx(stdscr, h, w) //畫(huà)背景 for(i=0 i<h i++) for(j=0 j<w j++){ mvaddch(i, j, ACS_CKBOARD) } refresh() //建立窗口 pad = newpad(80, 128) for(i=0 i<80 i++){ char line[128] sprintf(line, "This line in pad is numbered d\n", i) mvwprintw(pad, i, 0, line) } //刷新屏幕 refresh() prefresh(pad, 0, 1, 5, 10, 20, 45) for(i=0 i<50 i++){ prefresh(pad, i+1, 1, 5, 10, 20, 45) usleep(30000) } //等待按鍵 getch()
標(biāo)簽: getmaxyx initscr stdscr for
上傳時(shí)間: 2014-08-30
上傳用戶:龍飛艇
嚴(yán)格按照BP網(wǎng)絡(luò)計(jì)算公式來(lái)設(shè)計(jì)的一個(gè)matlab程序,對(duì)BP網(wǎng)絡(luò)進(jìn)行了優(yōu)化設(shè)計(jì) 優(yōu)化1:設(shè)計(jì)了yyy,即在o(k)計(jì)算公式時(shí),當(dāng)網(wǎng)絡(luò)進(jìn)入平坦區(qū)時(shí)(<0.0001)學(xué)習(xí)率加大,出來(lái)后學(xué)習(xí)率又還原 優(yōu)化2:v(i,j)=v(i,j)+deltv(i,j)+a*dv(i,j)
標(biāo)簽: matlab yyy BP網(wǎng)絡(luò) 計(jì)算公式
上傳時(shí)間: 2014-11-30
上傳用戶:妄想演繹師
實(shí)驗(yàn)源代碼 //Warshall.cpp #include<stdio.h> void warshall(int k,int n) { int i , j, t; int temp[20][20]; for(int a=0;a<k;a++) { printf("請(qǐng)輸入矩陣第%d 行元素:",a); for(int b=0;b<n;b++) { scanf ("%d",&temp[a][b]); } } for(i=0;i<k;i++){ for( j=0;j<k;j++){ if(temp[ j][i]==1) { for(t=0;t<n;t++) { temp[ j][t]=temp[i][t]||temp[ j][t]; } } } } printf("可傳遞閉包關(guān)系矩陣是:\n"); for(i=0;i<k;i++) { for( j=0;j<n;j++) { printf("%d", temp[i][ j]); } printf("\n"); } } void main() { printf("利用 Warshall 算法求二元關(guān)系的可傳遞閉包\n"); void warshall(int,int); int k , n; printf("請(qǐng)輸入矩陣的行數(shù) i: "); scanf("%d",&k); 四川大學(xué)實(shí)驗(yàn)報(bào)告 printf("請(qǐng)輸入矩陣的列數(shù) j: "); scanf("%d",&n); warshall(k,n); }
標(biāo)簽: warshall 離散 實(shí)驗(yàn)
上傳時(shí)間: 2016-06-27
上傳用戶:梁雪文以
Computation of loudness (Zwicker model) according to ISO 532B / DIN 45631 norms. This model is valid for steady sounds. Code based on BASIC program published in the following article: Program for calculating loudness according to DIN 45 631 (ISO 532B)", E.Zwicker and H.Fastl, J.A.S.J (E) 12, 1 (1991).
上傳時(shí)間: 2016-11-14
上傳用戶:zztony16
void DFS(MGraph G, int i) { int j; visited[i] = TRUE; printf("%c ", G.vexs[i]); for (j=0; j<G.numVertexes; ++j) { if (G.arc[i][j]!=INFINITY && !visited[j]) DFS(G, j); } }
標(biāo)簽: 多項(xiàng)式 代碼 計(jì)算
上傳時(shí)間: 2016-12-28
上傳用戶:chenyameng
蟲(chóng)蟲(chóng)下載站版權(quán)所有 京ICP備2021023401號(hào)-1