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. oc精简笔记

    首先如果是想在终端学习的话,以下内容是必须的,如果是直接使用xcode的请随意: operating system      os       X ter   终端的缩写 ls      显示目录文件 ...

  2. supervisor(三)xml_rpc

    supervisor提供的两种管理方式,supervisorctl和web其实都是通过xml_rpc来实现的. xml_rpc其实就是本地可以去调用远端的函数方法,然后函数方法经过一番处理后,把结果返 ...

  3. thinkphp几个表的数据合并,并用数组分页

    控制器: //金币扣除 public function jbkc(){ $map['UG_dataType']= 'xtkc'; $list1 = M ( 'userget' )->where ...

  4. nginx日志中文变成类型\xE9\xA6\x96\xE9\xA1\xB5-\xE6\x8E\xA8\xE8\x8D\x90的东西

    感谢 http://my.oschina.net/leejun2005/blog/106791 代码如下: public class App { public static String str2He ...

  5. LoadRunner测试场景中添加负载生成器

    如何在LoadRunner测试场景中添加负载生成器 本文对如何在LoadRunner的测试场景中添加负载生成器,如何使用负载生成器的方法,总结形成操作指导手册,以指导测试人员指导开展相关工作. 1.什 ...

  6. Console.log,Window.alert,Document.write三者区别

    1.Console.log不会阻断程序继续进行,在控制台可以看到测试结果. 2.Window.alert弹出框会阻断程序运行,在弹出框可以看到测试结果. 3.Document.write不会阻断程序继 ...

  7. https://www.nginx.com/blog/introduction-to-microservices/

    https://www.nginx.com/blog/introduction-to-microservices/

  8. ora-14400插入的分区关键字未映射到任何分区---oracle数据库表过期问题

    楼主解决这个问题ora-14400插入的分区关键字未映射到任何分区,其原因是:分区表过期. 通过使用sql直接修改Date类型的字段可以证实,修改成过期以后的时间出现下列提示,修改成过期之前的则可以. ...

  9. BZOJ4385 : [POI2015]Wilcze doły

    求出前缀和$s$,设$f[i]=s[i+d-1]-s[i-1]$. 从左到右枚举的右端点$i$,左端点$j$满足单调性,若$s[i]-s[j-1]-\max(区间内最大的f)\leq p$,则可行. ...

  10. eclipse svn proxy

    C:\Users\userName\AppData\Roaming\Subversion下的servers文件, 将#http-proxy-host和#http-proxy-port这两行前面的#号去 ...