吃土豆

时间限制: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. [LeetCode] 29. Divide Two Integers(不使用乘除取模,求两数相除) ☆☆☆

    转载:https://blog.csdn.net/Lynn_Baby/article/details/80624180 Given two integers dividend and divisor, ...

  2. 深入理解MyBatis中的一级缓存与二级缓存

    http://blog.csdn.net/weixin_36380516/article/details/73194758   先说缓存,合理使用缓存是优化中最常见的,将从数据库中查询出来的数据放入缓 ...

  3. [转载]oracle游标概念讲解

    原文URL:http://www.2cto.com/database/201203/122387.html ORACLE游标概念讲解 什么是游标?  ①从表中检索出结果集,从中每次指向一条记录进行交互 ...

  4. trycatch之catch对捕获异常的处理及后续代码的执行的探索

    工作时,一直对try块中throw的异常对象,在catch中如何处理此异常,以及trycatchfinally完毕,程序是否就此停止还是继续运行很迷惑,于是参考网上的资料,自己写了些demo,去慢慢探 ...

  5. ipython与sublime调用其shell出现的问题

    本机电脑 win10 已安装python3.5 1.    直接在命令行运行 pip install ipython[all] 安装 ipython 安装完成后 在命令行输入 jupyter note ...

  6. 去掉“Windows文件保护”

    1.在“开始→运行”对话框中键入“gpedit.msc”,打开“本地计算机策略→计算机配置→管理模板→系统”窗口,找到“Windows文件保护”组,在右侧窗格中双击“设置Windows文件保护扫描”项 ...

  7. js写的一个HashMap

    1.脚本 /** * 模拟HashMap */ function HashMap(){ //定义长度 var length = 0; //创建一个对象 var obj = new Object(); ...

  8. 0117 面向对象OOP有关方法、类、构造方法及权限修饰符的练习

    public class juxing { //编写一个矩形类,将长与宽作为矩形类的属性,在构造方法中将长.宽初始化,定义一个成员方法求此矩形面积 int chang; int kuan; int m ...

  9. <小常识>

    1,DOS(磁盘操作系统) 2,人机交互: (1):图形化界面(Graphical User interface GUI), (2):命令行方式(Command Line Interface CLI) ...

  10. JavaScript事件漫谈

    内容概要: event对象,事件在多个浏览器中的兼容,事件的传播机制,JS自定义事件,jQuery的自定义事件的绑定与触发 Event对象 Event对象属于HTML DOM对象.Event 对象代表 ...