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. Nginx简单配置,部分来源于网络

    nginx.conf listener监听端口 server_name监听域名 location{}是用来为匹配的 URI 进行配置,URI 即语法中的“/uri/”.location  / { }匹 ...

  2. spring容器启动的加载过程(二)

    第六步: public abstract class AbstractApplicationContext extends DefaultResourceLoader implements Confi ...

  3. SpringMVC的视图解析器

    ViewResolver和View介绍 SpringMVC用于处理视图最重要的两个接口是ViewResolver和View.ViewResolver的主要作用是把一个逻辑上的视图名称解析为一个真正的视 ...

  4. go语言实现寻找最大子数组

    题目:给定一个数字序列,寻找其中各元素相加和最大的子数组 /* 寻找最大子数组go语言实现 */ package main import fmt "fmt" func main() ...

  5. AVFoundation下的视频分帧处理

    // // ViewController.m // VideoFrame // // Created by wiseman on 16/1/27. // Copyright (c) 2016年 wis ...

  6. svn地址如何更改

    1.先进入平时放的更新文件的位置 2.然后右键 选中TortoiseSVN中的Relocate修改里面的完了之后输入账号和密码就好了当然你要记得密码和账号

  7. sql 将表B中不存在表A的数据 插入到表A中

    insert into tableA select * from tableB b where not exists(select 1 from tableA a where a.id = b.id) ...

  8. 关于PS的一些总结

    1.设计给的图,单独用里边的个别图层 打开图 — 新建一个图层(ctrl+n) — (点开上面的窗口排列-垂直排列,左下边下边自动选择改成图层)—选择移动工具,选中要移动的图层,拉到新建文件夹中.  ...

  9. ZUFE OJ 2288 God Wang I

    Description God Wang 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GodW变换 对于一个数字n,该变换后的值GodW(n)为,先令X=n 第一步,如果X为个位数,G ...

  10. 自动加载U盘

    编辑/etc/fstab 比如想在开机的时候将/dev/sda1安装在/mnt 可以在/etc/fstab中加入一行 /dev/sda1   /mnt    ext3    defaults    0 ...