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. angular项目国际化配置(ngx-translate)

    原文 https://www.jianshu.com/p/7d1da3098625 大纲 1.认识ngx-translate 2.ngx-translate的配置步骤 3.ngx-translate的 ...

  2. php json字符串转为数组或对象

    从网上查到的方法是 用get_object_vars 把类类型转换成数组 然后在用foreach  遍历即可 $array = get_object_vars($test); $json= '[{&q ...

  3. js进阶 11-13 jquery如何包裹元素和去除元素外的包裹

    js进阶 11-13  jquery如何包裹元素和去除元素外的包裹 一.总结 一句话总结:wrap().wrapAll().unwrap().innerWrap()四个方法 1.jquery中unwr ...

  4. Java IO流经典练习题(mark用)

    一.练习的题目 (一) 在电脑D盘下创建一个文件为HelloWorld.txt文件,判断他是文件还是目录,在创建一个目录IOTest,之后将HelloWorld.txt移动到IOTest目录下去:之后 ...

  5. ios开发不能不知的动态修复bug补丁第三方库JSPatch 使用学习:JSPatch导入、和使用、.js文件传输加解密

    JSPatch ios开发不能不知的动态修复bug补丁第三方库JSPatch 使用学习:JSPatch导入.和使用..js文件传输加解密 ios开发面临审核周期长,修复bug延迟等让人无奈的问题,所以 ...

  6. VO对象通过groovy模板映射XML文件

    介绍 之前写过JAVA+XSLT相关的技术博客,近期研究了一个开源工具包org.codehaus.groovy,处理VO对象和XML文件映射很方便. 简言之:将VO对象中的属性(包含Collectio ...

  7. 代码包结构分析工具JDepend的使用方法

    JDepend可以对Java软件包结构质量进行分析,已经有很多文章介绍其基本作用和能够计算的指标了,这里我就不详细总结,感兴趣的朋友可以参看如:http://blog.csdn.net/hantian ...

  8. 01_Git的安装和简单使用(命令行模式+图形化模式)

      刚开始用git的小白适用,参考链接:http://www.cnblogs.com/qijunjun/p/7137207.html  实际项目开发中,我们经常会用一些版本控制器来托管自己的代码,今天 ...

  9. 语言的学习 —— 西班牙语(español)

    联合国六大官方语言:英语.法语.俄语.汉语.西班牙语.阿拉伯语: 在七大洲中,主要是在拉丁美洲国家中(巴西.伯利兹.法属圭亚那.海地等地除外).很多说西班牙语的人把他们的语言称为西班牙语(españo ...

  10. 利用WPF建立自己的3d gis软件(非axhost方式)(二)基础状态切换

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(二)基础状态切换   先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bPew 密 ...