Beans

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

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
 
题意:
每一个格子有一个豆子,豆子有质量,每一行相邻的两个豆子不能同时选必须相隔,每一列也不能同时选,选了一列的某几个豆子则它的上一列和下一列不能选,问最多选到的豆子质量。
代码:
 /*
两次dp,算出每一行的最大值,再用每一行的最大值组成一列算出这列的最大值即可。
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
int n,m;
int x[];
int dp[][];
int a[];
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(x,,sizeof(x));
for(int i=;i<=n;i++)
{
memset(dp,,sizeof(dp));
for(int j=;j<=m;j++)
{
scanf("%d",&a[j]);
}
dp[][]=a[];
dp[][]=;
for(int j=;j<=m;j++)
{
dp[j][]=dp[j-][]+a[j];
dp[j][]=max(dp[j-][],dp[j-][]);
}
x[i]=max(dp[m][],dp[m][]);
}
memset(dp,,sizeof(dp));
dp[][]=x[];
dp[][]=;
for(int i=;i<=n;i++)
{
dp[i][]=dp[i-][]+x[i];
dp[i][]=max(dp[i-][],dp[i-][]);
}
int sum=max(dp[n][],dp[n][]);
printf("%d\n",sum);
}
return ;
}

HDU2845 DP的更多相关文章

  1. 假期训练七(hdu-2845 dp,hdu-1846,2188 巴什博奕)

    题目一:传送门 思路:动态规划,从每一行来看,每次更新求出这一点的最大值,dp[i]=MAX(dp[i-1],dp[i]+dp[i-2]),不会出现 两个数字相邻的情况:先对行进行更新,再对列进行更新 ...

  2. hdu2845(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2845 题意:给你一个n*m的矩阵,每个位置有一定数量的豆子,如果你去map[x][y]位置上的豆子,则 ...

  3. DP总结 ——QPH

    常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一 ...

  4. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  5. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  6. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  7. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  8. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  9. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

随机推荐

  1. cocoaPads 安装及出现Analyzing dependencies之后卡死解决方案

    1.安装 a. 查看源 gem sources -l b. 设置源: sudo gem sources -a http://ruby.taobao.org c. 删除源:sudo gem source ...

  2. Arduino101学习笔记(五)—— 模拟IO

    1.配置IO管脚 //***************************************************************************************** ...

  3. 快速幂 fast_exp

    long long fast_exp(int base,long long exp,int mod) { long long ans=1LL,a=base; ) { if(exp&1LL) a ...

  4. 基线 css

    原文地址:http://blog.jobbole.com/31926/ 英文原文:CSS Baseline,编译:飞鸟分享 译者注:网页设计布局中一直比较流行网格对齐,但只是针对水平的对齐,很少或者没 ...

  5. hdu1078 dp(递推)+搜索

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1078 题意:老鼠从(1.1)点出发,每次最多只能走K步,而且下一步走的位置的值必须必当前值 ...

  6. Swift3.0语言教程替换子字符串

    Swift3.0语言教程替换子字符串 Swift3.0语言教程替换子字符串,替换子字符串其实就是将字符串中的子字符串删除,然后再进行添加.为了让这一繁琐的过程变的简单,NSString提供了替换子字符 ...

  7. JS日期函数

    JS的日期函数有以下几个: getFullYear(); //获取当前年 getMonth(); //获取当前月,需要加1,而且只有一位数字,如果小于10需要前面加0 getDate(); //获取当 ...

  8. http://blog.csdn.net/u010246789/article/details/52539576

    http://blog.csdn.net/u010246789/article/details/52539576

  9. Python学习笔记08

      正则表达式包re match,search,sub re.match(pattern, string, flags=0) re.search(pattern, string, flags=0) r ...

  10. Linux下使用vsftp

    参考网址: http://wenku.baidu.com/view/4339434bc850ad02de80419c.html?re=view root用户无法ftp登录,显示530 Permissi ...