吃土豆

时间限制: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. hdu1864(01包)

    最大报销额 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  2. unity3d 博客

    博客: 1.http://my.csdn.net/caoboya 2.http://my.csdn.net/OnafioO

  3. JAVA System.arraycopy 和Arrays.copyof 效率比较

    System.arraycopy()源码.可以看到是native方法: native关键字说明其修饰的方法是一个原生态方法,方法对应的实现不是在当前文件,而是在用其他语言(如C和C++)实现的文件中. ...

  4. conv1d UpSampling1D aotoencoder 自编码代码摘录

    https://www.quora.com/How-do-I-implement-a-1D-Convolutional-autoencoder-in-Keras-for-numerical-datas ...

  5. Word发布到cnblogs文章

        1◆ 打开word 2◆ 注册用户   3◆ 操作 success

  6. [转]MVC Html.AntiForgeryToken() 防止CSRF攻击

    [转]MVC Html.AntiForgeryToken() 防止CSRF攻击 本文转自:http://blog.csdn.net/luck901229/article/details/8261640 ...

  7. SQL 查询重复的行

    select * from tbsold where orderid in (select orderid from tbsold group by orderid having count(orde ...

  8. Pycharm(二)创建项目

    首次打开就是这样,可以创建新项目,打开一个项目,也可以从版本控制打开项目 我们就新建项目吧,Create New Project 创建项目就是这样了 Location:项目路径. Interprete ...

  9. ACdream 1067:Triangles

    Problem Description 已知一个圆的圆周被N个点分成了N段等长圆弧,求任意取三个点,组成锐角三角形的个数. Input 多组数据,每组数据一个N(N <= 1000000) Ou ...

  10. 了解SAGA

    萨迦(尤指古代挪威或冰岛讲述冒险经历和英雄业绩的长篇故事)