NYOJ 234 吃土豆(基础dp)
吃土豆
- 描述
-
Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different qualities beans. Meantime, there is only one bean in any 1*1 grid. Now you want to eat the beans and collect the qualities, but everyone must obey by the following rules: if you eat the bean at the coordinate(x, y), you can’t eat the beans anyway at the coordinates listed (if exiting): (x, y-1), (x, y+1), and the both rows whose abscissas are x-1 and x+1.
Now, how much qualities can you eat and then get ?
- 输入
- There are a few cases. In each case, there are two integer M (row number) and N (column number). The next M lines each contain N integers, representing the qualities of the beans. We can make sure that the quality of bean isn't beyond 1000, and 1<=M,N<=500.
- 输出
- For each case, you just output the MAX qualities you can eat and then get.
- 样例输入
-
4 6 11 0 7 5 13 9 78 4 81 6 22 4 1 40 9 34 16 10 11 22 0 33 39 6
- 样例输出
-
242
//横向dp,最后纵向dp注意最后的max
#include<iostream>
#include<algorithm>
#include<cstdio>using namespace std;
int map[500+10][500+10]={0};
int main()
{int m,n;while(cin>>m>>n){for(int i=1; i<=m; i++)for(int j=1; j<=n; j++)cin>>map[i][j];for(int i=1; i<=m; i++){for(int j=3; j<=n; j++){map[i][j]+=max(map[i][j-2],map[i][j-3]);}map[i][n]=max(map[i][n],map[i][n-1]);//注意是在两个间取最大}for(int i=3; i<=m; i++){map[i][n]+=max(map[i-3][n],map[i-2][n]);}printf("%d\n",max(map[m][n],map[m-1][n]));}return 0;
}//ac
NYOJ 234 吃土豆(基础dp)相关推荐
- nyoj 234 吃土豆
描述 Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different q ...
- kuangbin专题十二 基础DP
kuangbin专题十二 基础DP A - HDU1024 Max Sum Plus Plus B - HDU1029 Ignatius and the Princess IV C - HDU1069 ...
- poj3666(基础dp+离散化)
题目链接:http://poj.org/problem?id=3666 Making the Grade Time Limit: 1000MS Memory Limit: 65536K Total ...
- 【算法模板】动态规划(基础DP篇)
[算法模板]动态规划(基础DP篇)
- 团队暑期集训 - 基础DP练习
目录 A - Max Sum Plus Plus D - 做作业(状态压缩) E - Super Jumping! Jumping! Jumping! I - 最少拦截系统(最长上升子序列模板) 团队 ...
- 【bzoj1742】[Usaco2005 nov]Grazing on the Run 边跑边吃草 区间dp
题目描述 John养了一只叫Joseph的奶牛.一次她去放牛,来到一个非常长的一片地,上面有N块地方长了茂盛的草.我们可以认为草地是一个数轴上的一些点.Joseph看到这些草非常兴奋,它想把它们全部吃 ...
- bzoj 1694 1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草(DP)
1742: [Usaco2005 nov]Grazing on the Run 边跑边吃草 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 395 So ...
- 牛客练习赛59 小松鼠吃松果(优化dp二维偏序)
小松鼠吃松果 非常nicenicenice的一道题 首先考虑dpdpdp 容易想到按照时间来排序 然后定义dp[i]dp[i]dp[i]为考虑前iii个果子且吃掉第iii个的最大价值 那么每次都去前面 ...
- 【基础dp】HRBUST 1861 猥琐宅男——koko
猥琐宅男--koko Time Limit: 1000 MS Memory Limit: 32768 K Description 唔..从前有个小胖子叫koko(QAQ...)很喜欢吃香蕉,茄子和黄瓜 ...
- Grid (基础DP)
题目: 给一个 H×W 的网格,网格由'.'和'#'组成,一开始在左上角 (1,1)(1,1) 每一步只能向右或向下走,不能经过 '#' 格子,求走到右下角 (H,W) 有多少种走法. 其中 2< ...
最新文章
- iOS开源程序下载链接整理
- 学python买什么书好-python官方推荐30本面向初学者的书籍!你看过几本?
- IO-BufferedInputStream
- 中石油训练赛 - One-Way Conveyors(边双缩点+树上差分)
- 思科路由PPPOE基本配置
- md /mdd /ml /mt/mtd
- mysql自增id用完了_MySQL 自增 ID 用完了怎么办?
- json 字符串反序列化成DataSet
- Wp keyword link 标签自动内链/文章关键词内链 WordPress插件
- 大数据_Spark_框架简介---Spark工作笔记0001
- Spring自动注入的几种方式
- 流程图绘制软件 EDraw Mind Map
- Allwinner(全志)V3s Camera sensor Support List
- 如果您已经熟悉K8s,现在不妨试试K9s
- java 创建txt_java创建txt文件并存入内容
- 宏定义超过字长的一些问题
- android 模拟内存不足,雷电模拟器内存不足怎么办?雷电安卓模拟器怎么修改内存大小?...
- http://fir.im免费发布内测版app和用企业版证书发布app
- 2021年茶艺师(初级)考试资料及茶艺师(初级)考试技巧
- 蓝魔w41原版 android 4.1固件,DX160固件Android8.1V1.04.150