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 ...
随机推荐
- TortoiseGit和msysGit安装及使用笔记(windows下使用上传数据到GitHub)[转]
TortoiseGit和msysGit安装及使用笔记(windows下使用上传数据到GitHub) Git-1.7.11-preview+GitExtensions244SetupComplete+T ...
- [Angular 2] Refactoring mutations to enforce immutable data in Angular 2
When a Todo property updates, you still must create a new Array of Todos and assign a new reference. ...
- Swift开放StatsD后上传数据的出现,出现退换货503的Bug
转载请注明出处:http://blog.csdn.net/cywosp/article/details/40781569 swift在版本号2.1.0之前假设各个服务的配置文件里打开下面配置后,且系统 ...
- [Linux 小技巧] Ubuntu 14.04 下编译、安装、配置最新开发版 GoldenDict
1. 背景介绍 GoldenDict 是一款非常优秀的跨平台电子词典软件,支持 StarDict.Babylon 等多种词典.其 PC 版基于 Qt 编写,完全免费.开源且没有广告.GoldenDic ...
- sublime text3中的常用插件
1.All Autocomplete Sublime Text 默认的 Autocomplete 功能只考虑当前的文件,而 AllAutocomplete 插件会搜索所有打开的文件来寻找匹配的提示词. ...
- Oracle11g主要服务程序
Oracle Orcl VSS Writer Service:Oracle对 VSS(卷影)的支持服务.Oracle卷映射拷贝写入服务VSS(Volume Shadow Copy Service)能够 ...
- Android-操作栏之图标导航
想实现图标向上导航功能,步子分两步走: 1.样式上要改变-->图标要变成可点击的按钮,并有一个向左的箭头. 2.功能上要实现-->实现向上导航 首先谈第一步: 对于拥有fragment的a ...
- Google map实现类似Google earth的图标展开功能
前言 在Google map的开发时,如果有多个图标重叠在一起,这时下面的图标就点击不到.而在Google Earth中,鼠标一移到上面就会自动弹开,这对于用户而言是十分人性化的一个功能.如下是在Go ...
- 学习npm和gulp的一些资料,先记着明天接着学习
Unix命令行程序和内建指令(百度百科) 将less编译成css的gulp插件 淘宝cnpm镜像 gulp教程之gulp-less gulp入门指南 查找npm的package.json的name配置 ...
- scala 入门(1)
大数据“火”的有段日子了,原来打算学习hadoop…… 后知道spark要比hadoop更牛, 故而转学spark.其原码为scala所写,为了更好的研究spark,故又开始学习scala. 将自己所 ...