吃土豆

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
描述
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)相关推荐

  1. nyoj 234 吃土豆

    描述 Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different q ...

  2. kuangbin专题十二 基础DP

    kuangbin专题十二 基础DP A - HDU1024 Max Sum Plus Plus B - HDU1029 Ignatius and the Princess IV C - HDU1069 ...

  3. poj3666(基础dp+离散化)

    题目链接:http://poj.org/problem?id=3666 Making the Grade Time Limit: 1000MS   Memory Limit: 65536K Total ...

  4. 【算法模板】动态规划(基础DP篇)

    [算法模板]动态规划(基础DP篇)

  5. 团队暑期集训 - 基础DP练习

    目录 A - Max Sum Plus Plus D - 做作业(状态压缩) E - Super Jumping! Jumping! Jumping! I - 最少拦截系统(最长上升子序列模板) 团队 ...

  6. 【bzoj1742】[Usaco2005 nov]Grazing on the Run 边跑边吃草 区间dp

    题目描述 John养了一只叫Joseph的奶牛.一次她去放牛,来到一个非常长的一片地,上面有N块地方长了茂盛的草.我们可以认为草地是一个数轴上的一些点.Joseph看到这些草非常兴奋,它想把它们全部吃 ...

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

  8. 牛客练习赛59 小松鼠吃松果(优化dp二维偏序)

    小松鼠吃松果 非常nicenicenice的一道题 首先考虑dpdpdp 容易想到按照时间来排序 然后定义dp[i]dp[i]dp[i]为考虑前iii个果子且吃掉第iii个的最大价值 那么每次都去前面 ...

  9. 【基础dp】HRBUST 1861 猥琐宅男——koko

    猥琐宅男--koko Time Limit: 1000 MS Memory Limit: 32768 K Description 唔..从前有个小胖子叫koko(QAQ...)很喜欢吃香蕉,茄子和黄瓜 ...

  10. Grid (基础DP)

    题目: 给一个 H×W 的网格,网格由'.'和'#'组成,一开始在左上角 (1,1)(1,1) 每一步只能向右或向下走,不能经过 '#' 格子,求走到右下角 (H,W) 有多少种走法. 其中 2< ...

最新文章

  1. iOS开源程序下载链接整理
  2. 学python买什么书好-python官方推荐30本面向初学者的书籍!你看过几本?
  3. IO-BufferedInputStream
  4. 中石油训练赛 - One-Way Conveyors(边双缩点+树上差分)
  5. 思科路由PPPOE基本配置
  6. md /mdd /ml /mt/mtd
  7. mysql自增id用完了_MySQL 自增 ID 用完了怎么办?
  8. json 字符串反序列化成DataSet
  9. Wp keyword link 标签自动内链/文章关键词内链 WordPress插件
  10. 大数据_Spark_框架简介---Spark工作笔记0001
  11. Spring自动注入的几种方式
  12. 流程图绘制软件 EDraw Mind Map
  13. Allwinner(全志)V3s Camera sensor Support List
  14. 如果您已经熟悉K8s,现在不妨试试K9s
  15. java 创建txt_java创建txt文件并存入内容
  16. 宏定义超过字长的一些问题
  17. android 模拟内存不足,雷电模拟器内存不足怎么办?雷电安卓模拟器怎么修改内存大小?...
  18. http://fir.im免费发布内测版app和用企业版证书发布app
  19. 2021年茶艺师(初级)考试资料及茶艺师(初级)考试技巧
  20. 蓝魔w41原版 android 4.1固件,DX160固件Android8.1V1.04.150

热门文章

  1. php测试页面打开速度,在JS中如何测试目标网站的打开响应速度
  2. 粉笔公考——错题集——申论
  3. 何为血缘分析?血缘分析能给我们带来什么影响?
  4. LOB浅析(CLOB/BCLOB/NCLOB)
  5. 【转】JavaScript面向对象程序设计(6): 封装
  6. C/C++实现贪吃蛇游戏
  7. iOS开发-代替UDID被弃用和UUID使用缺陷的解决方案
  8. Carla自动驾驶强化学习
  9. Joyful Pandas--综合练习
  10. 使用PIE下载Sentinel-2 时序NDVI数据