吃土豆

时间限制: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. 『Scrapy』爬取斗鱼主播头像

    分析目标 爬取的是斗鱼主播头像,示范使用的URL似乎是个移动接口(下文有提到),理由是网页主页属于动态页面,爬取难度陡升,当然爬取斗鱼主播头像这么恶趣味的事也不是我的兴趣...... 目标URL如下, ...

  2. RAC配置(启停库)

    关库顺序 :先关闭数据库 然后关闭节点资源 [root@rac1 ~]# srvctl stop   database  -d 数据库名[root@rac1 ~]# srvctl stop   ins ...

  3. dp练习(1)——马走日字

    3328: 马走日字 时间限制: 1 Sec  内存限制: 128 MB提交: 35  解决: 5[提交][状态][讨论版] 题目描述 一次外出旅游,你路上遇到了一个骑着马的强盗,你很害怕,你需要找一 ...

  4. ubuntu下没有Language Support

    sudo apt-get installlanguage-selector-gnome

  5. dubbo监控中心搭建

    从网上下载了一个dubbo监控中心,地址忘了,文件名是dubbo-monitor-simple-2.5.3-assembly.tar.gz. 修改监控中心配置文件如下: dubbo.container ...

  6. js获取当前点击元素的索引

    以ul下的li元素为例:获取li的索引,代码如下: <ul id="list"> <li></li> <li></li> ...

  7. spring boot 学习(九)小工具篇:?秒防刷新

    注解 + 拦截器:?秒防刷新 小工具篇:工具许多都是我以前在 github 之类开源平台找到的小工具类,作者的信息什么的许多都忘了.先说声不好意思了.若有相关信息,麻烦提醒一下~ 解释 所谓的?秒防刷 ...

  8. PHP:第四章——PHP数组查找,替换,过滤,判断相关函数

    <pre> <?php //查找,替换,过滤,判断相关函数 header("Content-Type:text/html;charset=utf-8"); /*知 ...

  9. jsp 自定义标签库

    自定义标签的作用 *** 自定义标签的主要用于移除jsp页面中java代码 *** JSP页面中使用自定义的标签 使用jsp指令<% @taglib uri="标签库的uri" ...

  10. Automatic Login Using sshpass

    #! /bin/bash user=root password=12345678 remote_ip=192.168.3.140 sshpass -p $password ssh $user@$rem ...