吃土豆

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述
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 ?

 
输入
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<=500.
输出
For each case, you just output the MAX qualities you can eat and then get.
样例输入
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

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;

int a[505][505];

int main()
{
int m,n;
while(cin>>m>>n)
{
memset(a,0,sizeof(a));
freopen("1.txt","r",stdin);
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
int Max;
for(int i=0;i<m;i++)
{
Max=a[i][n-1];
for(int j=n-1;j>=0;j--)
{
a[i][j]+=max(a[i][j+2],a[i][j+3]);
Max=max(Max,a[i][j]);
}
a[i][0]=Max;
}

Max=a[0][0];
a[2][0]+=a[0][0];
for(int i=3;i<m;i++)
{
a[i][0]+=max(a[i-2][0],a[i-3][0]);
Max=max(Max,a[i][0]);
}
cout<<Max<<endl;
}
return 0;
}

思路:

题目大意是如果某个土豆吃了,他的上下左右就不能吃了。

所以可以先对每行求最大。放在每行的行首,

再对第一列求最大。

数的不连续的和的最大值


nyoj 吃土豆的更多相关文章

  1. nyoj 234 吃土豆

    描述 Bean-eating * grid. Now you want to eat the beans and collect the qualities, but everyone must ob ...

  2. nyoj234 吃土豆 01背包

    思路:假设我们先只考虑一行,规则就是取了i处的土豆,每一个土豆有两种选择,拿与不拿,那么i-1和i+1处的土豆都不能再取,那么要求某一行的最大取值就用一次动态规划即可,dp(i)表示前i个土豆能取得的 ...

  3. 设计模式(二)简单工厂模式(Simple Factory Pattern)

    一.引言 这个系列也是自己对设计模式的一些学习笔记,希望对一些初学设计模式的人有所帮助的,在上一个专题中介绍了单例模式,在这个专题中继续为大家介绍一个比较容易理解的模式——简单工厂模式. 二.简单工厂 ...

  4. head first 设计模式读书笔记 之 策略模式

    作为一个php开发者,深知曾经很多程序员都鄙视php,为什么呢?因为他们认为php的语法是dirty的,并且由于开发者水平参差不齐导致php的代码更加乱上加乱,维护起来简直一坨shit一样.随着php ...

  5. C#设计模式之二简单工厂模式(过渡模式)

    一.引言 之所以写这个系列,是了为了自己更好的理解设计模式,也为新手提供一些帮助,我都是用最简单的.最生活化的实例来说明.在上一篇文章中讲解了单例模式,今天就给大家讲一个比较简单的模式--简单工厂模式 ...

  6. gensim和jieba分词进行主题分析,文本相似度

    参考链接:https://blog.csdn.net/whzhcahzxh/article/details/17528261 demo1:结巴分词: # 构造分词库,格式如下: ''' [['楼下', ...

  7. ThreadPoolExecutor 入参 corePoolSize 和 maximumPoolSize 的联系

    前言 我们可以通过 java.util.concurrent.ThreadPoolExecutor 来创建一个线程池: new ThreadPoolExecutor(corePoolSize, max ...

  8. C#设计模式(2)——简单工厂模式(转)

    C#设计模式(2)——简单工厂模式   一.引言 这个系列也是自己对设计模式的一些学习笔记,希望对一些初学设计模式的人有所帮助的,在上一个专题中介绍了单例模式,在这个专题中继续为大家介绍一个比较容易理 ...

  9. gensim做主题模型

    作为Python的一个库,gensim给了文本主题模型足够的方便,像他自己的介绍一样,topic modelling for humans 具体的tutorial可以参看他的官方网页,当然是全英文的, ...

随机推荐

  1. hdu 1069 DAG加权

    题目: Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  2. java.net.SocketException: Broken pipe

    java.net.SocketException: Broken pipe 生产上遇到一个问题,socket发生Broken pipe错误,如下 这个问题跟踪了好几个月,始终没有模拟出为什么会发生Br ...

  3. 流媒体传输协议详解之---RTSP认证

    from:http://blog.csdn.net/machh/article/details/52121648 Rtsp认证主要分为两种:   基本认证(basic authentication)和 ...

  4. 亿图图示与visio结合使用

    亿图图示与visio结合使用 Model 图例   思维导图 Camp Awards 思维导图 思维导图 Englilsh camp activity plan 项目管理 Auto WBS 商务 错误 ...

  5. learning docker steps(1) ----- docker 安装

    docker 安装 参考:https://docs.docker.com/install/linux/docker-ce/ubuntu/ 按如下指令可安装: $ sudo apt-get instal ...

  6. Flask 学习资源

    http://docs.jinkan.org/docs/flask/quickstart.html

  7. Struts2工作原理及流程

    Struts2是基于MVC设计模式的JavaWeb 框架技术. 基于Struts2开发Java Web项目的主要步骤如下: (1)在web.xml中配置FilterDispatcher. (2)设计和 ...

  8. (C/C++学习笔记) 十四. 动态分配

    十四. 动态分配 ● C语言实现动态数组 C语言实现动态数组,克服静态数组大小固定的缺陷 C语言中,数组长度必须在创建数组时指定,并且只能是一个常数,不能是变量.一旦定义了一个数组,系统将为它分配一个 ...

  9. JQ延迟对象

    延迟对象初识 技术一般水平有限,有什么错的地方,望大家指正. ES6已经实现了延迟对象Promise,但是今天主角是JQ里面的延迟对象,套路其实都是差不多的.下面先看一个比较牵强的例子: <bu ...

  10. websevice之三要素

    SOAP(Simple Object Access Protocol).WSDL(WebServicesDescriptionLanguage).UDDI(UniversalDescriptionDi ...