标签:
Sample Input 1 1 2 3 2 3 100 1 2 3 4 5 6 Sample Output 0 16 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 (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.
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5234
************************************************
题意:
分析:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <stack> 7 #include <map> 8 #include <vector> 9 using namespace std; 10 11 #define N 110 12 #define INF 0x3f3f3f3f 13 14 int maps[200][200],dp[N][N][N]; 15 16 int main() 17 { 18 int n,i,j,m,kk,k,x,y; 19 20 while(scanf("%d %d %d", &n,&m,&kk) != EOF) 21 { 22 memset(dp,0,sizeof(dp)); 23 memset(maps,0,sizeof(maps)); 24 25 for(i=1; i<=n; i++) 26 for(j=1; j<=m; j++) 27 scanf("%d", &maps[i][j]); 28 29 for(i=1; i<=n; i++) 30 for(j=1; j<=m; j++) 31 for(k=0; k<=kk; k++) 32 { 33 if(k<maps[i][j]) 34 dp[i][j][k]=max(dp[i-1][j][k], dp[i][j-1][k]); 35 else 36 { 37 x=max(dp[i-1][j][k-maps[i][j]], dp[i][j-1][k-maps[i][j]])+maps[i][j]; 38 y=max(dp[i-1][j][k], dp[i][j-1][k]); 39 dp[i][j][k]=max(x, y); 40 } 41 } 42 43 printf("%d\n", dp[n][m][kk]); 44 } 45 return 0; 46 } 47 ///一般还真不咋想三维,%>_<%,一想就发现原来没那么复杂了,,呵呵哒
标签:
原文地址:http://www.cnblogs.com/weiyuan/p/5777153.html