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
 
Source
 

思路:注意状态转移方程。还有就是行的转移方程和列的相似。还有注意的是数组开大点

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; #define N 200005 int dpx[N],dpy[N]; int main()
{
int n,m,i,j,s; while(~scanf("%d%d",&n,&m))
{
memset(dpx,0,sizeof(dpx));
memset(dpy,0,sizeof(dpy)); for(i=2;i<=n+1;i++)
{ //memset(dpy,0,sizeof(dpy));
//这里为什么能够凝视掉呢,由于会被覆盖 for(j=2;j<=m+1;j++)
{
scanf("%d",&s);
dpy[j]=max(dpy[j-1],dpy[j-2]+s); //dpy表示这一行从左到右能取到的最大的数和
}
dpx[i]=max(dpx[i-1],dpx[i-2]+dpy[1+m]); //dpx表示从以上行中能取到数的最大的和
} printf("%d\n",dpx[n+1]);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 2845 Beans(dp)的更多相关文章

  1. HDU 2845 Beans (DP)

    Problem Description Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled ...

  2. 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 ...

  3. HDU 3008 Warcraft(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...

  4. hdu 2059 龟兔赛跑(dp)

    龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...

  5. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. HDU 4945 2048(dp)

    题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...

  7. HDU 2340 Obfuscation(dp)

    题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...

  8. hdu 2571 命运(dp)

    Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个 ...

  9. HDU 6170----Two strings(DP)

    题目链接 Problem Description Giving two strings and you should judge if they are matched.The first strin ...

随机推荐

  1. (十一)RabbitMQ消息队列-如何实现高可用

    原文:(十一)RabbitMQ消息队列-如何实现高可用 在前面讲到了RabbitMQ高可用集群的搭建,但是我们知道只是集群的高可用并不能保证应用在使用消息队列时完全没有问题,例如如果应用连接的Rabb ...

  2. auto_create_partition

    #!/usr/bin/env python # -*- encoding: utf8 -*- import calendar import time import os import sys from ...

  3. Spring MVC学习:配置简解

    http://blog.csdn.net/heirenheiren/article/details/41485485

  4. linux mysql 卸载,安装,測试全过程

    Mysql卸载 yum remove mysql mysql-server mysql-libs compat-mysql51 rm -rf /var/lib/mysql rm /etc/my.cnf ...

  5. 树莓派——root用户和sudo

    Linux操作系统是一个多用户操作系统,它同意多个用户登录和使用一台计算机. 为了保护计算机(和其它用户的隐私).用户都被限制了能做的事情. 大多数用户都同意执行计算机上大部分程序,而且编辑和保存存放 ...

  6. iOS 日志自动上报

       您好,欢迎使用腾讯Bugly!腾讯Bugly是腾讯公司为移动开发者开放的服务之一. 针对移动应用,腾讯Bugly提供了专业的Crash(崩溃).Android ANR(application n ...

  7. java生成二维码,读取(解析)二维码图片

    二维码分为好多种,我们最常用的是qrcode类型的二维码,以下有三种生成方式以及解析方式: 附所需jar包或者js地址 第一种:依赖qrcode.jar import java.awt.Color; ...

  8. 【Dijkstra+邻接表求次短路】POJ Sightseeing 3463

    Language: Default Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7766   Ac ...

  9. 再续FPGA初心,京微齐力脱胎京微雅格重新起航(700万元天使轮,泰有基金领投,水木基金、臻云创投、泰科源跟投。数千万元Pre-A轮融资,领投方为海康基金)

    集微网消息,新的一年开启新的希望,新的空白承载新的梦想.这是年初一集微网给读者们拜年时写的寄语.在中国农历新年开年之际,半导体产业里也迎来了许多新的起点.例如长江存储在与苹果就采购前者的Nand闪存芯 ...

  10. Android 开发者工具

    30多个Android 开发者工具 文中部分工具是收费的,但是绝大多数都是免费的. FlowUp 这是一个帮助你跟踪app整体性能的工具,深入分析关键的性能数据如FPS, 内存, CPU, 磁盘, 等 ...