Topic Links:
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234
bc:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=585&pid=1003
Exercises
Because the data is relatively small, it can be converted into a judgment question, namely:
DP[I][J][KK] said go to i,j this point when eating the KK heavy cake, transfer equation just consider this point of cake to eat and not eat two cases (01 backpack)
Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 Const intmaxn=111;7 8 BOOLDP[MAXN][MAXN][MAXN];9 intARR[MAXN][MAXN];Ten intN,m,kilo; One A voidinit () { -Memset (DP,0,sizeof(DP)); - for(intI=0; i<maxn;i++){ the for(intj=0; j<maxn;j++){ -dp[i][j][0]=1; - } - } + } - + intMain () { A while(SCANF ("%d%d%d", &n,&m,&kilo) = =3&&N) { at init (); - for(intI=1; i<=n;i++){ - for(intj=1; j<=m;j++){ -scanf"%d",&arr[i][j]); - } - } in - for(intI=1; i<=n;i++){ to for(intj=1; j<=m;j++){ + for(intk=1; k<=kilo;k++){ - //(I,J) This cake does not eat thedp[i][j][k]=dp[i-1][j][k]|dp[i][j-1][k]; * //(i,j) Eat this cake $ if(k>=Arr[i][j]) {Panax Notoginsengdp[i][j][k]|=dp[i-1][j][k-Arr[i][j]]; -dp[i][j][k]|=dp[i][j-1][k-Arr[i][j]]; the } + } A } the } + - intans=0; $ for(inti=kilo;i>=0; i--){ $ if(Dp[n][m][i]) { -Ans=i; Break; - } the } -printf"%d\n", ans);Wuyi } the return 0; -}
HDU 5234 Happy Birthday 01 Backpack