Beans

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2596    Accepted Submission(s): 1279



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
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  2830 2577 2870 

pid=1159" target="_blank">1159 

pid=1176" target="_blank">1176

这道题意思能够转换成:
对每一行,不能有间隔的取一个子序列,即取该行的最大不连续子序列和;
再从上面全部值中,取其最大不连续子序列和;就相当于隔一行取了
状态:f[i]表示取第i个元素(a[i]必取)的最大值,map[i]表示取到a[i](可不取)时的最大值
状态转移:f[i]=map[i-2]+a[i];map[i]=max{map[i-1],f[i]};
#include <stdio.h>
#include <iostream>
using namespace std;
#define M 200001
int vis[M],map[M],dp[M],f[M];
int
max(int a[],int n) //求在a[]中最大不连续子序列和。
{
int i;
f[0]=map[0]=0;
f[1]=map[1]=a[1];
for(
i=2;i<=n;i++) //要保证i-2不会数组越界。
{

f[i]=map[i-2]+a[i]; //由于要隔一个取。所以取了a[i],就不能取a[i-1],所以最大值就是前i-2个数的最大值+a[i].
map[i]=f[i]>map[i-1]?f[i]:map[i-1]; //假设取a[i]要更大,更新map[i]的值。
}
 return
map[n];
}
int main(int
i,int j,int k)
{
int
n,m,tot,cur;
while(
scanf("%d%d",&n,&m)!=EOF&&n&&m)
{
for(
i=1;i<=n;i++)
{
for(
j=1;j<=m;j++)
scanf("%d",&vis[j]);
dp[i]=max(vis,m);
}

printf("%d\n",max(dp,n));
}
return
0;
}

 

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

HDU 2845 Beans (动态调节)的更多相关文章

  1. HDU 2845 Beans (DP)

    Beans Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  2. HDU 2845 Beans (两次线性dp)

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  3. HDU 2845 Beans(dp)

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

  4. Hdu 2845 Beans

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  5. HDU 2845 Beans (DP)

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

  6. hdu 2845 Beans(最大不连续子序列和)

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

  7. hdu 2845 Beans 2016-09-12 17:17 23人阅读 评论(0) 收藏

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  8. hdu 2845——Beans——————【dp】

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. HDU 2475 BOX 动态树 Link-Cut Tree

    Box Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem De ...

随机推荐

  1. [置顶] iframe使用总结(实战)

    说在前面的话,iframe是可以做很多事情的. 例如: a>通过iframe实现跨域; b>使用iframe解决IE6下select遮挡不住的问题 c>通过iframe解决Ajax的 ...

  2. Java使用Socket传输文件遇到的问题

    1.写了一个socket传输文件的程序,发现传输过去文件有问题.找了一下午终于似乎找到了原因,记录下来警示一下: 接受文件的一端,向本地写文件之前使用Thread.sleep(time)休息一下就解决 ...

  3. UVA1455 - Kingdom(并查集 + 线段树)

    UVA1455 - Kingdom(并查集 + 线段树) 题目链接 题目大意:一个平面内,给你n个整数点,两种类型的操作:road x y 把city x 和city y连接起来,line fnum ...

  4. fastdfs storage server的设计与实现

     fastdfs是一个针对互联网应用设计的分布式文件系统.具有架构简单.结构清晰.代码量小等特点. 详细的介绍及架构请參考分布式文件系统FastDFS架构剖析(http://www.program ...

  5. 阿里巴巴2015研究project普通笔试题,与答案

    欢迎您对这篇文章的其他建议.我可以留言在以下平台. 个人博客网站:www.anycodex.com/blog/ Csdn博客网站:http://my.csdn.net/?ref=toolbar 微博: ...

  6. MySql 安装及0基础使用具体解释

    1. sudo apt-get install mysql-server, input administrator password , '123' 2. enter mysql promot in ...

  7. poj3140(树的dfs)

    题目链接:http://poj.org/problem?id=3140 题意:给定一棵n棵节点的树,求删去某条边后两个分支的最小差异值. 分析:num[u]表示以u点为根节点的子树的总人数,那么不在该 ...

  8. 提供一个好用的Oracle Database 11g 下载地址

    提供一个好用的Oracle Database 11g 下载地址,在windows xp 操作系统下,测试通过. http://download.oracle.com/otn/nt/oracle11g/ ...

  9. GEF的MVC体系结构

    摘要: 本文首先介绍了标准的 MVC 体系构架,同时也介绍了最常见的一类 MVC 模式的变种.之后,文章重点介绍了 MVC 结构在 gef 框架中的体现与应用,以及 gef 是如何综合利用工厂模式.命 ...

  10. Swift的属性,方法,下标脚本以及继承

    从这篇章节起,Swift编程语言指南大部分的重要内容在于概念,代码并非太多.理解Swift的面向对象理念,语法以及类结构,构造析构过程对于非常好的应用Swift语言将会有比較大的帮助. 属性 存储属性 ...