Beans
2015-10-19 10:31
183 查看
Description
View Code
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.
#include <iostream> using namespace std; #define M 200005 int a[M], b[M]; int main() { int m, n, i, j; while (~scanf ("%d%d", &m, &n)) { for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) scanf ("%d", b+j); for (j = 2; j <= n; j++) b[j] = max (b[j-2]+b[j], b[j-1]); a[i] = b ; } for (i = 2; i <= m; i++) a[i] = max (a[i]+a[i-2], a[i-1]); printf ("%d\n", a[m]); } return 0; }
View Code
相关文章推荐
- jquery插件layer
- Java基本概念:集合类(Collection)List/Set/Map的区别和联系
- 数据结构——查找之二叉排序树
- oracle 定时器
- 开发该选择Blocks还是Delegates
- 关于独立完成已有iOS项目《疯狂食材》总结
- php+mysql分页原理
- [国嵌笔记][021-022][ARM处理器工作模式]
- Github开源项目收藏
- xcode错误:"The application could not be verified."
- XiaoBiuBiu
- 验证码部分的java代码
- 为Wordpress安装WP-PostViews插件
- 【July程序员编程艺术】之链表追赶问题
- FreeSWITCH基本应用
- 洛谷1373 小a和uim之大逃离
- linux中 include文件,放置目录路径
- 多数据源冲突的解决
- jodd,超全面强大,简洁的Email
- HEVC最优CU划分确定的过程