HDU 2845 Beans (DP)
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 ?
1000, and 1<=M*N<=200000.
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
242
题目能够看成是一个二维的,每一维的解法都是一个DP的过程。也就是一个数组,取第i个数就不能取与他相邻的数。求和最大。
能够设两个数组d[i],f[i]为别表示第i个数取或者不取时的和最大。
d[i] = f[i-1]+a[i] , f[i] = max(f[i-1],d[i-1]) 。
f[1] = 0, d[1] = a[1] .
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL;
const int MAX=0x3f3f3f3f;
const int maxn = 200005;
int n, m;
int d[maxn], f[maxn], a[maxn], b[maxn];
int DP(int *c, int len) {
d[1] = c[1], f[1] = 0;
for(int i = 1; i <= len; i++) {
d[i] = f[i-1] + c[i];
f[i] = max(f[i-1], d[i-1]);
}
return max(f[len], d[len]);
}
int main()
{
while(~scanf("%d%d", &n, &m)) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++)
scanf("%d", &a[j]);
b[i] = DP(a, m);
}
printf("%d\n", DP(b, n));
}
return 0;
}
HDU 2845 Beans (DP)的更多相关文章
- HDU 2845 Beans(dp)
Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...
- HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)
Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...
- HDU 3008 Warcraft(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...
- hdu 2059 龟兔赛跑(dp)
龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...
- HDU 4832 Chess (DP)
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4945 2048(dp)
题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...
- HDU 2340 Obfuscation(dp)
题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...
- hdu 2571 命运(dp)
Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个 ...
- HDU 6170----Two strings(DP)
题目链接 Problem Description Giving two strings and you should judge if they are matched.The first strin ...
随机推荐
- ViewController详解
一.生命周期 当一个视图控制器被创建,并在屏幕上显示的时候. 代码的执行顺序1. alloc 创建对象,分配空间2.init (initWit ...
- android源代码百度网盘分享
转载请标明出处: http://blog.csdn.net/yujun411522/article/details/46334123 本文出自:[yujun411522的博客] 近期在使用Ubunt ...
- PHP字符串的编码问题(转)
大家都知道,不同字符编码,其在内存占用的字节数不一样.如ASCII编码字符占用1个字节,UTF-8编码的中文字符是3字节,GBK为2个字节. PHP 也自带几种字符串截取函数,其中常用到的就是 s ...
- response和request
请求响应流程图 response response是用来向客户端响应的对象! 需要回忆一下http响应内容: l 首行:状态码 l 响应头: 1头1值,1头多值: l 响应体(正文):html ...
- javascriipt类型转换
- Asp.Net 下载文件的几种方式
asp.net下载文件几种方式 protected void Button1_Click(object sender, EventArgs e) { /* 微软为Response对象提供了一个新的方法 ...
- SQL从入门到基础–08 Union、Union all及案例
一.联合结果集 1. 简单的结果集联合: Select FNumber,FName,FAge from T_Employee union select FidCardNumber,FName,FAge ...
- C#中静态构造函数含义及使用
static以前都接触过,可是最近才发现了还有静态类的写法,也可能是以前没太注意了,所以自己去研究了一下! 1.什么是构造函数: 1.1 例如:static Class{} 1.2 使用静态函数的注 ...
- android sax解析xml 文件 动态加载标题
要解决一个问题 : 问题描述为 把标题动态的加载到 listView子布局中 我们首先通过 java程序写一个把标题写到xml文件的程序.这个程序会在以后讲解. 现在截图 已经写好的xm文件格式如下 ...
- C++中多重继承构造函数执行顺序
代码1: #include <cstdio> #include <iostream> using namespace std; class A{ public: A(){ co ...