Problem Description
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 ?

 
Input
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<=200000.
 
Output
For each case, you just output the MAX qualities you can eat and then get.
 
Sample Input
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
 
Sample Output
242
 
Source
 

思路:注意状态转移方程。还有就是行的转移方程和列的相似。还有注意的是数组开大点

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; #define N 200005 int dpx[N],dpy[N]; int main()
{
int n,m,i,j,s; while(~scanf("%d%d",&n,&m))
{
memset(dpx,0,sizeof(dpx));
memset(dpy,0,sizeof(dpy)); for(i=2;i<=n+1;i++)
{ //memset(dpy,0,sizeof(dpy));
//这里为什么能够凝视掉呢,由于会被覆盖 for(j=2;j<=m+1;j++)
{
scanf("%d",&s);
dpy[j]=max(dpy[j-1],dpy[j-2]+s); //dpy表示这一行从左到右能取到的最大的数和
}
dpx[i]=max(dpx[i-1],dpx[i-2]+dpy[1+m]); //dpx表示从以上行中能取到数的最大的和
} printf("%d\n",dpx[n+1]);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 2845 Beans(dp)的更多相关文章

  1. HDU 2845 Beans (DP)

    Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...

  2. HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)

    Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...

  3. HDU 3008 Warcraft(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...

  4. hdu 2059 龟兔赛跑(dp)

    龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...

  5. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. HDU 4945 2048(dp)

    题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...

  7. HDU 2340 Obfuscation(dp)

    题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...

  8. hdu 2571 命运(dp)

    Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个 ...

  9. HDU 6170----Two strings(DP)

    题目链接 Problem Description Giving two strings and you should judge if they are matched.The first strin ...

随机推荐

  1. C语言之基本算法11—牛顿迭代法求平方根

    //迭代法 /* ================================================================== 题目:牛顿迭代法求a的平方根!迭代公式:Xn+1 ...

  2. 并发队列ConcurrentLinkedQueue 和 阻塞队列LinkedBlockingQueue用法

    在Java多线程应用中,队列的使用率很高,多数生产消费模型的首选数据结构就是队列(先进先出).Java提供的线程安全的Queue可以分为阻塞队列和非阻塞队列,其中阻塞队列的典型例子是BlockingQ ...

  3. js进阶正则表达式方括号(方括号作用)(js正则是在双正斜杠之中:/[a-z]/g)

    js进阶正则表达式方括号(方括号作用)(js正则是在双正斜杠之中:/[a-z]/g) 一.总结 方括号:范围 圆括号:选 大括号:数量 1.js正则是在双正斜杠之中: var reg2=/[a-z]/ ...

  4. 博客搬家啦! -----> http://ronghaopger.github.io/

    新地方: http://ronghaopger.github.io/ 以后这里就不更新了,感谢博客园!

  5. JavaMail| JavaMail配置属性

    属性名 含义 mail.smtp.user SMTP的缺省用户名. mail.smtp.host 要连接的SMTP服务器. mail.smtp.port 要连接的SMTP服务器的端口号,如果conne ...

  6. [javase学习笔记]-6.6 基本数据类型參数与引用数据类型參数的传递过程

    这一节基本数据类型參数和引用数据类型參数的传递过程. 数据类型參数和引用參数我们在前面章节中都已涉及到了,那么我们来看看以下的两段代码: //基本数据类型參数传递 class Demo { publi ...

  7. 浏览器jsp、html之间的关系

    浏览器html.jsp之间的关系 1.HTML能直接通过浏览器打开,而JSP仅仅能公布到Tomcatserver才干打开. 2.HTML中不能嵌套Java代码,而JSP中能够嵌套Java代码: 3.H ...

  8. JavaStuNote 4

    装箱(inbox)和拆箱(outbox) 代表了类类型和基本类型之间的转换行为. 手动版本号: Integer b = new Integer(10); Int a = b.intValue; 自己主 ...

  9. Indy10 控件的使用(2)TidTCpServer组件学习

    以下来自英文原版帮助文件,文桓英语不好,翻译了老半天.有错误的地方见谅,别骂我. TIdTCPServer = class(TIdComponent) Description TIdTCPServer ...

  10. Static静态变量和非静态变量

    Static静态变量:   不同的对象共享这个变量的存储空间 而不是静态变量   每个对象具有可变的存储器空间 public class StaticDemo { private int count= ...