Beans

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2518    Accepted Submission(s): 1250

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

   题目的意思是给一个矩阵,没一点放置一定数量的豆,求出最多能吃多少个豆。但是吃豆有一定的规则,如果吃点(x,y)的豆,那么点(x,y-1)、点(x,y+1)和点(x,y)所在行的上一行和下一行的豆都不能吃。所以我们要做的事首先将每一行所能吃到的最大豆的数量求出来,即求出每一行非连续的最大子序列和,然后将每一行所求的最大豆数量保存到数组序列中,同样的方法求出数组序列的非连续的最大子序列和即为所能吃到的最大豆的数量。

  状态转移方程:sum[i] = dp[i-2]+a[i],dp[i] = max(sum[i],dp[i-1]),2<=i<=n,初始化sum[0]=dp[0]=0,sum[1]=dp[1]=a[1]。

我的代码:

 #include <iostream>
#include <cstdio>
using namespace std;
#define N 200003
int sum[N],dp[N],map[N],row[N]; int solve(int a[],int n)
{
int i;
sum[] = ;
dp[] = ;
sum[] = a[];
dp[] = a[];//数组dp代表最大豆的数量
for(i=; i<=n; i++)
{
sum[i] = dp[i-]+a[i];
dp[i] = max(sum[i],dp[i-]);
}
return dp[n];
} int main()
{
int i,j,n,m,sum;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=; i<=n; i++)
{
for(j=; j<=m; j++)
scanf("%d",&map[j]);
row[i] = solve(map,m);
}
sum = solve(row,n);
printf("%d\n",sum);
}
return ;
}

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 (动态调节)

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

  4. HDU 2845 Beans(dp)

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

  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 3037Saving Beans(卢卡斯定理)

    Saving Beans Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

随机推荐

  1. bzoj4196 [Noi2015]软件包管理器 树链剖分+线段树

    先把树剖分了(又是dfs1.dfs2),然后区间求和.区间覆盖即可 难得的1A好(shui)题 ——写了那么多题,终于有一道是1A的了,加上上一次连续交了几遍A的程序,我的状态莫名好看啊233 总结: ...

  2. CSS清除浮动八种方法

    在各种浏览器中显示效果也有可能不相同,这样让清除浮动更难了,下面总结8种清除浮动的方法,测试已通过 ie chrome firefox opera,需要的朋友可以参考下 清除浮动是每一个 web前台设 ...

  3. XMLHttpRequest对象用法

    xmlhttprequest is what? 用户后台与服务器交换数据. 可以在不重新加载页面的情况下更新网页: 在页面已加载后从服务器请求数据: 在页面已加载后从服务器接收数据: 在后台向服务器发 ...

  4. Android端接收和发送cookie

    流程: 首先android端使用HttpClient的方式发送HTTP请求,此时服务器创立cookie,并发送cookie给android端,android端再将cookie保存起来,在需要发送coo ...

  5. POST在发送数据的时候使用的是HTTP命令

    防止SQL注入 SQL(结构化查询语言)是基于美国国家标准学会(ANSI)标准,并作为共同的语言与数据库通信.每个数据库系统增加了一些专有功能到基本的ANSI SQL. SQL注入是一门将制作好的SQ ...

  6. 第一章-第二题Unity3D游戏引擎相关--By林培文

    1) 此类软件是什么时候开始出现的, 这些软件是怎么说服你(陌生人)成为他们的用户的?  他们的目标都是盈利么?  他们的目标都是赚取用户的现金么?还是别的? 2004年,Unity3D诞生于丹麦哥本 ...

  7. C fwrite

    功能:向文件读入写入一个数据块. 用法:fwrite(const void *buffer,size_t size,size_t count,FILE *stream); (1)buffer:是一个指 ...

  8. 在Windows 10下启用旧的照片查看器

    从Windows 10开始,默认只能通过“照片”来查看图片了,非常不方便!通过将下列文本保存在.reg文件后导入,即可找回Windows XP时代的“照片查看器”. Windows Registry ...

  9. buy

    <script type="text/javascript"> var is_enabled = -1; var checkSubmitFlg = false; var ...

  10. sqlserver 索引的一些总结【转】

    1.1.1 摘要 如果说要对数据库进行优化,我们主要可以通过以下五种方法,对数据库系统进行优化. 1. 计算机硬件调优 2. 应用程序调优 3. 数据库索引优化 4. SQL语句优化 5. 事务处理调 ...