http://acm.hdu.edu.cn/showproblem.php?pid=5234 1 1 2 //n,m,k(1--100) 3 2 3 100 1 2 3 4 5 6
Sample Output
0 16HintIn the first case, Gorwin can’t eat part of cake, so she can’t eat any cake. In the second case, Gorwin walks though below route (1,1)->(2,1)->(2,2)->(2,3). When she passes a grid, she eats up the cake in that grid. Thus the total amount cake she eats is 1+4+5+6=16. 题意:从(1,1)到(n,m)最大的且不超过k的最多蛋糕量。每个位置表示蛋糕量,只能往下或往右走,每个位置可以吃或不吃,没有其他情况。 位置(i,j)的只能从(i,j-1),(i-1,j)过来。 每个位置的所有状态可能对后面有用,所以对于每一个位置的所有状态我们都需要保存。 不妨设d【i】【j】【k】==1表示在位置i,j能吃蛋糕量为k,d【】【】【k】==0表示不能吃蛋糕量为k, if(d[i-1][j][t]==1) d[i][j][t]=1 d[i][j][t+value(i,j)]=1;