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 Submission(s): 4456 Accepted Submission(s): 2105
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 ?
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
题目的意思是在一个矩阵中取数字,取数规则是如果取了一个数a[i][j],那么他的上一行和下一行和前后两个数都不能取了。
处理时先在每一行算出最大不连续子序列的和,保存到一个数组里,当所有行都处理完之后,我们发现在列上也是一个球最大不连续子序列和的问题
由于数据较大,数组开不下,我们采用输一行处理一行
对于每个数dp[i]如果取它的话最大值一定是他到前面2个或3个的最大值加上他自己,即dp[i]=max(dp[i-2],dp[i-3])+a[i];因为i-1不能取,而i-4升至更大的话,中间空了一个可以取得数。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f int dp[200005];
int b[200005];
int a[200005];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
scanf("%d",&a[j]);
} dp[0]=a[0];
dp[1]=a[1];
dp[2]=dp[0]+a[2];
for(int j=3;j<m;j++)
{
dp[j]=max(dp[j-2],dp[j-3])+a[j];
}
b[i]=max(dp[m-1],dp[m-2]);
}
dp[0]=b[0];
dp[1]=b[1];
dp[2]=dp[0]+b[2];
for(int j=3;j<n;j++)
{
dp[j]=max(dp[j-2],dp[j-3])+b[j];
}
int ans=max(dp[n-1],dp[n-2]);
printf("%d\n",ans); } return 0;
}
hdu 2845 Beans 2016-09-12 17:17 23人阅读 评论(0) 收藏的更多相关文章
- Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- hdu 1232, disjoint set, linked list vs. rooted tree, a minor but substantial optimization for path c 分类: hdoj 2015-07-16 17:13 116人阅读 评论(0) 收藏
three version are provided. disjoint set, linked list version with weighted-union heuristic, rooted ...
- hdu 1031 (partial sort problem, nth_element, stable_partition, lambda expression) 分类: hdoj 2015-06-15 17:47 26人阅读 评论(0) 收藏
partial sort. first use std::nth_element to find pivot, then use std::stable_partition with the pivo ...
- APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏
APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...
- Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏
漫步校园 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏
The 3n + 1 problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53927 Accepted: 17 ...
- POJ3258 River Hopscotch 2017-05-11 17:58 36人阅读 评论(0) 收藏
River Hopscotch Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 5791 ...
- Speed Limit 分类: POJ 2015-06-09 17:47 9人阅读 评论(0) 收藏
Speed Limit Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 17967 Accepted: 12596 Des ...
随机推荐
- Technology, globalisation and the squeeze on good jobs
Technology, globalisation and the squeeze on good jobs技术与全球化冲击好工作“Highest stock market EVER! Jobs ar ...
- etcd 集群恢复
七个节点,挂了5个,etcd无法访问 参考: https://coreos.com/etcd/docs/latest/op-guide/recovery.html 此次我只恢复了v3的数据 在存活的节 ...
- Spring boot集成 MyBatis 通用Mapper
配置 POM文件 <parent> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- 用NBU无法还原数据库到ASM磁盘
描述:用NBU无法还原数据库到ASM磁盘,却可以还原到数据库本地磁盘 错误提示: ORA-15025: could not open disk "/dev/mapper/DATA1" ...
- springboot引入springSecurity无法post提交表单
参考https://blog.csdn.net/shawearn1027/article/details/71119587 表单中添加<input type="hidden" ...
- org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]
运行servlet程序报错: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Cat ...
- css写三角形
#triangle-up { width: 0; height: 0; border-left: 50px solid transparent; border-right: 5 ...
- cdoj203-Islands 【并查集】
http://acm.uestc.edu.cn/#/problem/show/203 Islands Time Limit: 30000/10000MS (Java/Others) Memor ...
- MyBatis高级查询
-------------------------siwuxie095 MyBatis 高级查询 1.MyBatis 作为一个 ORM 框架,也对 SQL 的高级查询做了支持, MyBatis 高级查 ...
- jQuery对象转换为DOM对象(转)
jQuery对象转换为dom对象 只有jQuery对象才能调用jQuery类库的各种函数,同样有些dom对象的属性和方法在jQuery上也是无法调用的,不过基本上jQuery类库提供的函数包含了所有的 ...