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
 
题意:在图中取数,例如取了81之后,同一行的相邻两个不能取,还有81的上面那行和下面那行也不能取,问能取到的最大和是多少?
思路:分别求行列的最大不连续子序列和
#include <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int sum[][];
int main(){
ios::sync_with_stdio(false);
int m,n;
while(cin>>m>>n){
for(int i=;i<=m;i++){
for(int j=;j<=n;j++){
cin>>sum[j][];
}
for(int j=;j<=n;j++)
sum[j][]=max(sum[j][]+sum[j-][],sum[j-][]);
sum[i][]=sum[n][];
}
for(int i=;i<=m;i++)
sum[i][]=max(sum[i][]+sum[i-][],sum[i-][]);
cout<<sum[m][]<<endl;
}
}

hdu 2845 Beans(最大不连续子序列和)的更多相关文章

  1. HDU 2845 Beans (动态调节)

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. HDU 2845 Beans (DP)

    Beans Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  3. hdu 2845 Beans 2016-09-12 17:17 23人阅读 评论(0) 收藏

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  4. HDU 2845 Beans (两次线性dp)

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  5. Hdu 2845 Beans

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. HDU 2845 Beans(dp)

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

  7. HDU 2845 Beans (DP)

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

  8. hdu 2845——Beans——————【dp】

    Beans Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. HDU 1159 Common Subsequence 公共子序列 DP 水题重温

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...

随机推荐

  1. [Oracle]包含了MVIEW的表领域,在进行导出,表领域改名,再导入后,MVIEW会消失不见。

    包含了MVIEW的表领域,在进行导出,表领域改名,再导入后,MVIEW会消失不见. 测试环境12.1.0.2 =================步骤1:数据的准备 [oracle@db12102 ad ...

  2. item 8: 比起0和NULL更偏爱nullptr

    本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 先让我们看一些概念:字面上的0是一个int,不是一个指针.如果C+ ...

  3. c++多继承布局

    1:多重继承 对于一个继承了多个base class 的对象,将其地址指定给最左端(也就是第一个)base class的指针, 情况将和单一继承时相同,因为两者都指向相同的其实地址.至于第二个或者更后 ...

  4. json中获取key值

    <script type="text/javascript"> getJson('age'); function getJson(key){ var jsonObj={ ...

  5. SQL多表查询总结

    前言 连接查询包括合并.内连接.外连接和交叉连接,如果涉及多表查询,了解这些连接的特点很重要.只有真正了解它们之间的区别,才能正确使用. 一.Union UNION 操作符用于合并两个或多个 SELE ...

  6. Install Jetty web server on CentOS 7 / RHEL 7

    http://www.eclipse.org/jetty/download.html http://www.eclipse.org/jetty/documentation/current/startu ...

  7. Appium学习笔记3_Genymotion模拟器安装

    如果你已经配置好了安卓的运行环境,也配置好了自带的模拟器AVD,而且也launch了你的安卓模拟器,那么我相信你是不再愿意launch安卓模拟器第二次了,因为实在是太卡了(当然如果你电脑的配置够高,你 ...

  8. [转帖]紫光展锐5G芯片

    紫光展锐5G芯片已流片:7nm工艺 2019年问世   https://news.mydrivers.com/1/612/612346.htm 本文转载自超能网,其他媒体转载需经超能网同意 高通骁龙X ...

  9. css CSS常见布局解决方案

    CSS常见布局解决方案说起css布局,那么一定得聊聊盒模型,清除浮动,position,display什么的,但本篇本不是讲这些基础知识的,而是给出各种布局的解决方案.水平居中布局首先我们来看看水平居 ...

  10. 周刷题第二期总结(Longest Substring Without Repeating Characters and Median of Two Sorted Arrays)

    这周前面刷题倒是蛮开心,后面出了很多别的事情和问题就去忙其他的,结果又只完成了最低目标. Lonest Substring Without Repeating Characters: Given a ...