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 ...
随机推荐
- MVC实现类似QQ的网页聊天功能-Ajax(上)
说到QQ聊天,程序员首先想到的就是如何实现长连接,及时的接收并回馈信息.那么首先想到的就是Ajax,Ajax的运行机制是通过XMLHttpRequest向服务器发出异步请求,并接受数据,这样就可以实现 ...
- ICE 介绍及实现
.ICE是什么? ICE是ZEROC的开源通信协议产品,它的全称是:The Internet Communications Engine,翻译为中文是互联网通信引擎,是一个面向对象的中间件,使我们能够 ...
- speex的基本编码和解码流程
最近在研究speex的编码和解码流程 之前在IM上用到的都是发语音片段,这个很简单,只需要找到googlecode上gauss的代码,然后套一下就可以用了. 不过googlecode要关闭,有人将他导 ...
- SVN服务器的本地搭建和使用
用VisualSVN server 服务端和 TortoiseSVN客户端搭配使用. 详细步骤如下 http://www.2cto.com/os/201412/361931.html
- mybati的存储过程
这里我就以的存储过程为例,大家一起学习一下,
- NumberBox( 数值输入框) 组件
本节课重点了解 EasyUI 中 NumberBox(数值输入框)组件的使用方法,这个组件依赖于 ValidateBox(验证框)组件.一. 加载方式//class 加载方式<input typ ...
- Cookie[1]
1.什么是Cookie Cookie是一小段文本类型的数据,由服务器发送,并保留在客户端的计算机上. 2.Cookie的作用 服务器可以利用Cookie包含的信息来筛选并经常维护这些信息,以判断在Ht ...
- java 后台线层也叫守护线层
import java.util.concurrent.locks.*; class Do9 { public static void main(String[] args) { Ds d=new D ...
- Linux下查看Apache的请求数
在Linux下查看Apache的负载情况,以前也说过,最简单有有效的方式就是查看Apache Server Status(如何开启Apache Server Status点这里),在没有开启Apach ...
- python学习第十五天 -面向对象之继承和多态
大家都知道面向对象的三大特性:封装,继承,多态.封装特性在上一章节已经讲解过.这一章节主要讲解继承和多态. 继承: 当定义一个类的时候,可以从现有的类进行继承.那么新定义的类可以称为子类,被继承的现有 ...