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 is wij 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.

 
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 integers wi1,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

 
Output
For each case, output an integer in an single line indicates the maximum weight of cake Gorwin can eat.
Sample Input

Sample Output

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 (,)->(,)->(,)->(,). When she passes a grid, she eats up the cake in that grid. Thus the total amount cake she eats is +++=.

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5234

************************************************

题意:

分析:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std; #define N 110
#define INF 0x3f3f3f3f int maps[][],dp[N][N][N]; int main()
{
int n,i,j,m,kk,k,x,y; while(scanf("%d %d %d", &n,&m,&kk) != EOF)
{
memset(dp,,sizeof(dp));
memset(maps,,sizeof(maps)); for(i=; i<=n; i++)
for(j=; j<=m; j++)
scanf("%d", &maps[i][j]); for(i=; i<=n; i++)
for(j=; j<=m; j++)
for(k=; k<=kk; k++)
{
if(k<maps[i][j])
dp[i][j][k]=max(dp[i-][j][k], dp[i][j-][k]);
else
{
x=max(dp[i-][j][k-maps[i][j]], dp[i][j-][k-maps[i][j]])+maps[i][j];
y=max(dp[i-][j][k], dp[i][j-][k]);
dp[i][j][k]=max(x, y);
}
} printf("%d\n", dp[n][m][kk]);
}
return ;
}
///一般还真不咋想三维,%>_<%,一想就发现原来没那么复杂了,,呵呵哒

HDU - 5234 Happy birthday的更多相关文章

  1. HDU 5234 Happy birthday --- 三维01背包

    HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置 ...

  2. HDU 5234 背包。

    J - 10 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. HDU 5234 Happy birthday 01背包

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  4. hdu 5234 Happy birthday 背包 dp

    Happy birthday Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  5. HDU 5234 DP背包

    题意:给一个n*m的矩阵,每个点是一个蛋糕的的重量,然后小明只能向右,向下走,求在不超过K千克的情况下,小明最终能吃得最大重量的蛋糕. 思路:类似背包DP: 状态转移方程:dp[i][j][k]--- ...

  6. HDU 5234 Happy birthday 动态规划(三维数组)

    题目大意:过生日,有一个N*M的表格,每个位置都有一块一定重量的蛋糕你可以选择吃完或者不吃,从(1,1)走到(n,m),每次只能向右走或向下走,最多能吃k重量的蛋糕.问你最多能吃多少蛋糕. 题目思路: ...

  7. HDU 5234 Happy birthday【DP】

    题意:给出n*m的格子,每个格子的值为w[i][j],在值不超过k的时候,可以往右或者往下走,问从(1,1)走到(n,m)能够得到的最大的值 类似于背包 d[i][j][k]=maxx(d[i-1][ ...

  8. (hdu)5234 Happy birthday 二维dp+01背包

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5234 Problem Description Today is Gorwin’s birt ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. Chapter7 迭代器

    结合泛型for的所有功能,写出更加简单,高效的迭代器. 1.迭代器和closure 迭代器是一种可以遍历集合中所有元素的机制.在Lua中用函数去表示它. 每调用一次,就返回下一个元素. 迭代器在两次成 ...

  2. 使用Apache + mod_jk + tomcat来实现tomcat集群的负载均衡出现的无法加载mod_jk.conf文件的问题

    用Apache + mod_jk + tomcat来实现tomcat集群的负载均衡的 如果出现了问题,可以用cmd  cd到Apache安装文件的bin下,运行httpd文件,错误信息就会打印出来. ...

  3. aforge之hough

    /// <summary> /// 参数不能是一位索引 /// </summary> /// <param name="bmp"></pa ...

  4. 查找一个数组中最小的前n项

    /****************************************************************** find the biggest x number in a s ...

  5. ios日期时间

    //1.获取当前时间 -(NSString*)getCurrentTime { NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; ...

  6. 如何直观的解释back propagation算法?

    转自:知乎-https://www.zhihu.com/question/27239198 作者:匿名用户链接:https://www.zhihu.com/question/27239198/answ ...

  7. sql server显示某一列中有重复值的行

    sql server查询一张表 ,显示某一列中有重复值的行,可以这样写: Select * From 表名 where 列名 in(Select 列名 From Table group by 列名 h ...

  8. redis持久化探究

    redis支持两种持久化方式,一种是RDB方式,另一种是AOF方式.redis3.0windows版本默认关闭AOF(appendonly no),而开启RDB,当达到一定条件时,redis就会将内存 ...

  9. Windows命令查看文件MD5码

    D:\>certutil -hashfile md5test.txt MD5 MD5 哈希(文件 md5test.txt): d6 f6 bb 38 b5 6b 67 8f 34 9b e4 d ...

  10. oracle日期的处理

    字符长转换为日期,有两种写法 SELECT date'2016-06-03' FROM dualselect to_date('2016-06-03','yyyy-mm-dd') from dual ...