HDU 2845 Beans (动态调节)
Beans
Total Submission(s): 2596 Accepted Submission(s): 1279
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 ?
1000, and 1<=M*N<=200000.
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
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 (动态调节)的更多相关文章
- HDU 2845 Beans (DP)
Beans Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 2845 Beans (两次线性dp)
Beans Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDU 2845 Beans(dp)
Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...
- Hdu 2845 Beans
Beans Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2845 Beans (DP)
Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...
- hdu 2845 Beans(最大不连续子序列和)
Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...
- 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 ...
- hdu 2845——Beans——————【dp】
Beans Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 2475 BOX 动态树 Link-Cut Tree
Box Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) [Problem De ...
随机推荐
- plsql导入一个目录下全部excel
import java.io.File; import java.util.ArrayList; import jxl.Sheet; import jxl.Workbook; import com.j ...
- PowerDesigner中SQL文件、数据库表反向生成PDM
1 反向生成PDM 1) 创建一个空的PDM模型(选择相应的DBMS): 2) 选择[Database]--[Update Model from Database ...
- Python 类继承,__bases__, __mro__, super
Python是面向对象的编程语言,也支持类继承. >>> class Base: ... pass ... >>> class Derived(Base): ... ...
- spring 定义自己的标签 学习
自己的自定义配置文件spring 在,有时你想要做一些配置信息的数据结构.基于扩展生意做. 首先: 在项目META-INF文件夹中创建两个文件spring.handlers,和spring.shcem ...
- Android Studio 入门(转)
本文适用于从Eclipse转AndroidStudio的开发者 最近打算写一个系列的android初级开发教程,预计40篇以上的文章,结合我实际工作中的经验,写一些工作中经常用到的技术,让初学者可以少 ...
- (转)一篇很不错的介绍Eclipse插件Menu及其扩展点的文章
原文在:http://tech.ddvip.com/2010-04/1271054623150507.html 菜单是各种软件及开发平台会提供的必备功能,Eclipse 也不例外,提供了丰富的菜单,包 ...
- Android四个多线程分析:MessageQueue实现
Android四个多线程分析:MessageQueue的实现 罗朝辉 (http://blog.csdn.net/kesalin) CC 许可,转载请注明出处 在前面两篇文章<Android多线 ...
- LeetCode——Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- php函数serialize()与unserialize() 数据序列化与反序列化
php函数serialize()与unserialize()说明及案例.想要将已序列化的字符串变回 PHP 的值,可使用unserialize().serialize()可处理除了resource之外 ...
- windows phone 页面传值(7)
原文:windows phone 页面传值(7) 在windows phone 中微软为我们提供了页面间传递参数的解决方案,下面就为大家介绍使用方法,页面传值的案例中我们建立两个页面,一个是MainP ...