HDU - 5234 Happy birthday
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.
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
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的更多相关文章
- HDU 5234 Happy birthday --- 三维01背包
HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置 ...
- HDU 5234 背包。
J - 10 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- HDU 5234 Happy birthday 01背包
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/con ...
- hdu 5234 Happy birthday 背包 dp
Happy birthday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 5234 DP背包
题意:给一个n*m的矩阵,每个点是一个蛋糕的的重量,然后小明只能向右,向下走,求在不超过K千克的情况下,小明最终能吃得最大重量的蛋糕. 思路:类似背包DP: 状态转移方程:dp[i][j][k]--- ...
- HDU 5234 Happy birthday 动态规划(三维数组)
题目大意:过生日,有一个N*M的表格,每个位置都有一块一定重量的蛋糕你可以选择吃完或者不吃,从(1,1)走到(n,m),每次只能向右走或向下走,最多能吃k重量的蛋糕.问你最多能吃多少蛋糕. 题目思路: ...
- HDU 5234 Happy birthday【DP】
题意:给出n*m的格子,每个格子的值为w[i][j],在值不超过k的时候,可以往右或者往下走,问从(1,1)走到(n,m)能够得到的最大的值 类似于背包 d[i][j][k]=maxx(d[i-1][ ...
- (hdu)5234 Happy birthday 二维dp+01背包
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5234 Problem Description Today is Gorwin’s birt ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- 局域网iis添加主机头
局域网上用主机头访问不像外网,直接设置主机头就行了, 在局域网设置了主机头还要修改host文件 打开host快捷的方法: win7在win+r运行里面运行C:\Windows\System32\dri ...
- layoutSubview触发时机
layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews 2.addSubview会触发layoutSubviews 3.设置view的Frame会触 ...
- javascript动画效果之多物体缓冲运动
这个是通过一个for循环控制的三个li标签,被鼠标触发则会有一个宽度增加和减少的事件 html和css同样写在一起方便察看,这里就是简单的布局,重点在js <!DOCTYPE html> ...
- Value '0000-00-00' can not be represented as java.sql.Date
Value '0000-00-00' can not be represented as java.sql.Date 时间 2014-07-30 09:00:50 ITeye-博客 原文 http: ...
- zabbix3.2在lamp环境安装
zabbix官网下载zabbix-3.2.1.tar.gz wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20 ...
- JavaScript(5)——DOM
DOM操作 为了写这一篇随笔真的是费了好多力气,虽然还是写不好.本来是从周一都开始写的,但是周二周三忙着去帮忙招新了,哈哈哈.感觉做自己喜欢的事特别好玩,虽然挺忙的.看着那些小鲜肉,感觉自己真的老了啊 ...
- 会话技术cookie和session详解
什么是会话 会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 会话技术解决了什么问题 每个用户与服务器进行交互的过程中,各自会有一 ...
- WKWebView与Js交互
首先打开webstorm,将最下面h5拷贝到html中.然后导入工程 #define kMessageHandlerName @"mymobile" 1.创建配置类 - (WKWe ...
- 开源日志系统比较:scribe、chukwa、kafka、flume
1. 背景介绍 许多公司的平台每天会产生大量的日志(一般为流式数据,如,搜索引擎的pv,查询等),处理这些日志需要特定的日志系统,一般而言,这些系统需要具有以下特征: (1) 构建应用系统和分析系统的 ...
- 12.04 ubuntu 进入登录界面,账号密码确定是正确的但是进不来系统。
很简单,HOME目录存储太多东西了,导致开机不了.