HDU2845 DP
Beans
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4451 Accepted Submission(s): 2103
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 ?
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.
/*
两次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的更多相关文章
- 假期训练七(hdu-2845 dp,hdu-1846,2188 巴什博奕)
题目一:传送门 思路:动态规划,从每一行来看,每次更新求出这一点的最大值,dp[i]=MAX(dp[i-1],dp[i]+dp[i-2]),不会出现 两个数字相邻的情况:先对行进行更新,再对列进行更新 ...
- hdu2845(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2845 题意:给你一个n*m的矩阵,每个位置有一定数量的豆子,如果你去map[x][y]位置上的豆子,则 ...
- DP总结 ——QPH
常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一 ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 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 ...
- AEAI DP V3.7.0 发布,开源综合应用开发平台
1 升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...
- AEAI DP V3.6.0 升级说明,开源综合应用开发平台
AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- [斜率优化DP]【学习笔记】【更新中】
参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...
随机推荐
- Codeforces Round #333 (Div. 1) D. Acyclic Organic Compounds trie树合并
D. Acyclic Organic Compounds You are given a tree T with n vertices (numbered 1 through n) and a l ...
- 关于转换大写中文金额-新学的java函数整理
toCharArray public char[] toCharArray() 将此字符串转换为一个新的字符数组. 返回: 一个新分配的字符数组,它的长度是此字符串的长度,而且内容被初始化为包含此字符 ...
- 配置tomcat下war包可以自压缩
<Host name="localhost" appBase="/home/hark/web" unpackWARs="true" a ...
- java中 几种数据库连接池 的写法
JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.l ...
- cf 二分图
题目链接:http://vjudge.net/contest/133033#problem/C 题目大意:给你n个点,m条边,将其分成两个集合,集合A是图的一个点覆盖,集合B也是图的一个点覆盖,要求集 ...
- poj 1321 棋盘问题
八皇后问题变形,回溯法. #include <cstdio> #include <cstring> #include <iostream> using namesp ...
- iOS10 UI教程视图的绘制与视图控制器和视图
iOS10 UI教程视图的绘制与视图控制器和视图 iOS10 UI视图的绘制 iOS10 UI教程视图的绘制与视图控制器和视图,在iOS中,有很多的绘图应用.这些应用大多是在UIView上进行绘制的. ...
- js总结-面向对象编程,DOM,BOM
- 【面试题】HWL
1.编程题 设计数据结构,模拟浏览器功能: BACK FORWARD VISIT QUIT Visit 未指定具体网址时,返回主页 http://www.xueersi.com 2.指出下列程序的错误 ...
- 原生 js 左右切换轮播图
使用方法: 可能很多人对轮播图感兴趣,下面奉上本人的 原生 js 轮播代码复制 js 到页面的最底部,样式在 css 里改,js 基本不用动,有什么不懂的可以 加本人 QQ172360937 咨询 或 ...