HDU 5234
Title: Given n,m,k, and the number of N*m (n Rows M column), K is the backpack capacity, starting from (a) can only go down or to the right, in order to reach (M,n) can obtain the maximum value
Solution: Dp[i][j][k] Indicates the maximum value of a backpack with a capacity of K in position (I,J)
Decision: Whether the number is selected at A[i][j]
Not selected: dp[i][j][k]= Max (Dp[i-1][j][k], dp[i][j-1][k])
Select: First request K >=a[i][j], then dp[i][j][k] = Max (Dp[i-1][j][k-w[i][j]], dp[i][j-1][k-w[i][j]);
Equal to the maximum value of the four, and finally dp[m][n][k] is the result of the request
/*HDU 5234 Happy Birthday---three-dimensional 01 backpack*/#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intMAXN = the;intW[MAXN][MAXN];intDP[MAXN][MAXN][MAXN];intN, M, V;intMain () {#ifdef _local freopen ("D:\\input.txt","R", stdin);#endif //n row m column capacity is v while(SCANF ("%d%d%d", &n, &m, &v) = =3){ for(inti =1; I <= N; ++i) { for(intj =1; J <= M; ++j) {scanf ("%d", W[i] +j); }//For (j)}//For (i)memset (DP,0,sizeofDP); for(inti =1; I <= N; ++i) { for(intj =1; J <= M; ++j) { for(intK =0; K <= V; ++k) { //W[i][j] No time to take intA = max (Dp[i-1][J][K], Dp[i][j-1][k]); intb =0; //k > W[i][j], w[i][j] take the time if(K-w[i][j] >=0) {b= Max (Dp[i-1][J][K-W[I][J]], dp[i][j-1][K-W[I][J]]) +W[i][j]; } Dp[i][j][k]=Max (A, b); } }//For (j)}//For (i)printf ("%d\n", Dp[n][m][v]); } return 0;}View Code
HDU 5234 Happy Birthday---three-dimensional 01 backpack