Description
Today is Gorwin ' s birthday. So she mother want to realize her a wish. Gorwin says that she wants to eat many cakes. Thus, her mother takes she to a cake garden.
The garden was splited into n*m grids. In each grids, there is a cake. The weight of cake in the i-th row j-th column are ${w_{ij}}$ kilos, Gorwin starts from the Top-left (a) grid of the Garde N and walk to the Bottom-right (n,m) grid. In each step Gorwin can go to right or down, i.e when Gorwin stands in (i,j), then she can go to (i+1,j) or (i,j+1) (Howev Er, she can not be go out of the garden).
When Gorwin reachs a grid, she can eat up the cake in that grid or just leave it alone. However she can ' t eat part of the cake. But Gorwin's belly is not very large, so she can eat at the most K kilos cake. Now, Gorwin have stood in the Top-left grid and look at the "Map of the garden" she want to find a route which can leads her To eat most cake. But the map was so complicated. So she's wants you.
Input
Multiple test cases, every case gives N, M, K
In the next n lines, the i-th line contains m integers ${w_{i1}},{w_{i{\rm{2}}}},{w_{i3}}, \cdots {w_{im}}$ which describe s the weight of cakes in the i-th row
Please process to the end of file.
[Technical specification]
All inputs is integers.
1<=n,m,k<=100
1<=${w_{ij}}$<=100
Output
For each case, output a integer in a single line indicates the maximum weight of cake gorwin can eat.
Sample Input
1 1 232 3 1001 2 34 5 6
Sample Output
11W
Hint
In 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 (+ 2,1)--(2,2). 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.Mean:give a n*m matrix, each point is the weight of a cake,then Gorwin can only go to the right, down, in the case of no more than k kg, Gorwin finally can eat the maximum weight of the cake.
Anlayse:similar backpack DP;
State transfer equation: dp[i][j][k]----at the i,j position, the maximum capacity is the maximum value of k;
#include <cstdio>#include<cstring>#include<iostream>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intmaxn=109;Const intinf=0x3f3f3f3f;Const intMod= the;intDP[MAXN][MAXN][MAXN];intNUM[MAXN][MAXN];intMain () {intN, M, K; while(~SCANF (" %d%d%d", &n, &m, &k)) { for(intI=1; i<=n; i++) for(intj=1; j<=m; J + +) scanf ("%d", &Num[i][j]); Memset (DP,0,sizeof(DP)); for(intI=1; i<=n; i++) { for(intj=1; j<=m; J + +) { for(intZ=k; z>=num[i][j]; z--) { intX=max (dp[i-1][j][z], dp[i][j-1][z]); intY=max (dp[i-1][J][Z-NUM[I][J]]+NUM[I][J], dp[i][j-1][z-num[i][j]]+Num[i][j]); DP[I][J][Z]=Max (x, y); }}} printf ("%d\n", Dp[n][m][k]); } return 0;}
HDU---5234---Happy birthday