hdu-5234(dp)
来源:互联网 发布:东北软件学院地址 编辑:程序博客网 时间:2024/05/02 02:43
Happy birthday
Problem Description
Today is Gorwin’s birthday. So her mother want to realize her a wish. Gorwin says that she wants to eat many cakes. Thus, her mother takes her to a cake garden.
The garden is splited into n*m grids. In each grids, there is a cake. The weight of cake in the i-th row j-th column iswij kilos, Gorwin starts from the top-left(1,1) grid of the garden 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) (However, she can not 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 most K kilos cake. Now, Gorwin has stood in the top-left grid and look at the map of the garden, she want to find a route which can lead her to eat most cake. But the map is so complicated. So she wants you to help her.
The garden is splited into n*m grids. In each grids, there is a cake. The weight of cake in the i-th row j-th column is
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 most K kilos cake. Now, Gorwin has stood in the top-left grid and look at the map of the garden, she want to find a route which can lead her to eat most cake. But the map is so complicated. So she wants you to help her.
Input
Multiple test cases (about 15), every case gives n, m, K in a single line.
In the next n lines, the i-th line contains m integerswi1,wi2,wi3,⋯wim which describes the weight of cakes in the i-th row
Please process to the end of file.
[Technical Specification]
All inputs are integers.
1<=n,m,K<=100
1<=wij <=100
In the next n lines, the i-th line contains m integers
Please process to the end of file.
[Technical Specification]
All inputs are integers.
1<=n,m,K<=100
1<=
Output
For each case, output an integer in an single line indicates the maximum weight of cake Gorwin can eat.
Sample Input
1 1 232 3 1001 2 34 5 6
Sample Output
题意:map[n][m]中,每个坐标有一定质量蛋糕,从(1,1)走到(n,m),只可以向左或下走,问吃不超过k质量的蛋糕最多吃多少。每个位置的蛋糕只能不吃或全吃。016
思路:
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<map>#include<vector>#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;int dp[105][105][105];int mp[105][105];int n,m,k;bool cango(int x,int y){ if(x<1||x>n||y<1||y>m) return false; return true;}int main(){ while(~scanf("%d%d%d",&n,&m,&k)) { memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) scanf("%d",&mp[i][j]); } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { for(int kk=1;kk<=k;kk++) { if(kk==mp[i][j]) dp[i][j][kk]=kk; else{ if(cango(i-1,j)) dp[i][j][kk]=max(dp[i][j][kk],dp[i-1][j][kk]); if(cango(i,j-1)) dp[i][j][kk]=max(dp[i][j][kk],dp[i][j-1][kk]); if(kk>mp[i][j]){ dp[i][j][kk]=max(mp[i][j],dp[i][j][kk]); if(cango(i-1,j)) dp[i][j][kk]=max(dp[i][j][kk],dp[i-1][j][kk-mp[i][j]]+mp[i][j]); if(cango(i,j-1)) dp[i][j][kk]=max(dp[i][j][kk],dp[i][j-1][kk-mp[i][j]]+mp[i][j]); } } } } } printf("%d\n",dp[n][m][k]); } return 0;}
0 0
- hdu-5234(dp)
- HDU 1024(DP)
- HDU 1087(DP)
- HDU 1506(DP)
- hdu 1058 (DP)
- hdu 1208 (DP)
- hdu 4502(DP)
- hdu 4561(DP)
- hdu 1292 (dp)
- hdu 2182 (dp)
- hdu 2955(DP)
- hdu 2546(dp)
- hdu 3466 (dp)
- hdu 3186(dp)
- hdu 1203(dp)
- hdu 2881(dp)
- hdu 2126(dp)
- hdu 4648(dp)
- android开发运行程序出现stop
- 【Java学习笔记】一个初学者的学习历程,分享学习JAVA心得
- [Emacs学习笔记]入门:移动光标的N种方法
- java字符串查找替换
- ckeditor image align center customization(ckeditor 编辑器图像属性居中设置)
- hdu-5234(dp)
- treap
- 目标跟踪__好的网站
- java中byte数组与int,long,short间的转换
- cdoj1091
- 得到ImageView的图片,压缩成PNG,并得到二进制流数据
- 第十一周项目0-是春哥啊
- Codeforces #200(div.2) 模拟练习赛
- 大才非学不成,大志非学不就——周旭龙