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. Codeforces Round #370 (Div. 2) D. Memory and Scores DP

    D. Memory and Scores   Memory and his friend Lexa are competing to get higher score in one popular c ...

  2. 构造函数创建对象和Object.create()实现继承

    第一个方法用构造函数创建对象,实现方法的继承 /*创建一个对象把所有公用的属性和方法,放进去*/ function Person() { this.name = "W3cplus" ...

  3. android应用程序如何调用支付宝接口

    最近在做一个关于购物商城的项目,项目里面付款这块我选的是调用支付宝的接口,因为用的人比较多. 在网上搜索了以下,有很多这方面的教程,但大部分教程过于陈旧,而且描述的过于简单.而且支付宝提供的接口一直在 ...

  4. codeforces 286 div2 B

    思路:质因子累乘的值即为所求#include<iostream> #include<algorithm> #include<stdio.h> #include< ...

  5. loadrunner中变量和参数之间的转化实例

     1.变量转换成参数值的两种方法: 方法一: char *test="Agoly"; lr_save_string(test,"testPa");   lr_e ...

  6. 网页打印A4纸-----表格在跨页时自动换页打印的实现 (转)

    在最近所做的一个项目中,需要通过网页来打印不少的表单,但是又不想每个打印页签各占用一个页面,这样就需要生存很多不同的冗余页面,为了减少冗余,所有的表单通过jquery的页签tab来实现的. 一 :基本 ...

  7. Uva 839 Not so Mobile

    0.最后输出的yes no的大小写 1.注意 递归边界   一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...

  8. SU demos

  9. Chage

    For many times,i've given my own a new lifestyle,such as don't stay up late,have breakfast......whil ...

  10. BZOJ3485 : [Baltic2012]peaks

    首先将每个平原缩成一个点,建出图,相邻两个点之间的边权为它们高度的较小值. 用Kruskal算法求出这个图的最大生成树,每次合并两个连通块时新建一个点指向它们,得到一棵有根树. 对于每个点,求出它子树 ...