dp[i][j]=max{dp[i-1][j-v[i]]+c[i],dp[i-1][j]};
for (I =. 1; I <= n-; I ++ ) { for (J = v [i]; J <= V; J ++) { // Note that this is the v [i] starts to V IF (J> = V [I]) DP [J] = max {DP [J], DP [JV [I]] + C [I]}; } }
dp[j]=max{dp[j],dp[j-v[i]]+c[i]};
dp [i] [j] = max {dp [i-1] [vk * v [i]] + k * c [] | 0 <= k <= n [i]}; (k denotes the i items into pieces k);
for(i=1;i<=n;i++){ for(j=v;j>=0;j--){ for(k=1;k<=n[i];k++){ if(j>=k*v[i]) dp[i][j]=max(dp[i-1][v-k*v[i]]+k*c[i]) } }
f(4) = f(3) + f(2) + f(1);
Longest common subsequence: The nature of the longest common subsequence problem, we may specify DP [i] [j] is the longest common subsequence first j characters before i-th character string 1 and string 2 length, since below relate to I -1 and j-1, so this time we generally from i = 1 and j = 1 to start I <= LEN1, J <= LEN2. I CHl [I -1] = CH2 [-J. 1], then dp [i] [j] = dp [i-1] [j-1] + 1;
All this time, i = dp [i] 0 or j = 0 to [J] = 0 ; 0; I = 0 or j = 0 ; have DP = DP [I] [J] DP = [. 1-I] [ j-1] + 1; i > 0 and j> 0 and CHl [I-. 1] = CH2 [J-. 1 ]; DP [I] [J] = max {DP [I-. 1] [J], DP [i] [j-1] }; i> 0 and j> 0 and ch1 [i-1] = ch2 [j-1]!;
3 , and issues the maximum subsequence Given a sequence a1, a2 .......... an; Qiuzi sequence biggest problems and dp [i] denotes the end of the sub-sequence and ai, max is the maximum sequence and core: if the input data is a maximum value of all the negative sequence is the maximum of a 2 if positive for (I = 1; I <= n-; I ++ ) { DP [I] = DP [I -1] + AI; IF (DP [I] <0 ) DP [I] = 0 ; IF (max < DP [I]) max = DP [I]; }
2 , the maximum ascending or descending sequence given a sequence A1, A2 .......... AN; DP [I] represents the length of the longest sequence ai the end of the rising (falling opposite) core code: for (I =. 1; I <= n-; I ++ ) { DP [I] =. 1 ; for (K =. 1; K <I; K ++ ) { IF (AK <AI && DP [I] <DP [K] + 1'd ) DP [I] = DP [K] + 1'd ; } }