The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the ACM Finals this year). This is the place where the astronauts are trained for Mission Seven Dwarfs, the next giant leap in space exploration. The Mars Odyssey program revealed that the surface of Mars is very rich in yeyenum and bloggium. These minerals are important ingredients for certain revolutionary new medicines, but they are extremely rare on Earth. The aim of Mission Seven Dwarfs is to mine these minerals on Mars and bring them back to Earth.

The Mars Odyssey orbiter identified a rectangular area on the surface of Mars that is rich in minerals. The area is divided into cells that form a matrix of n <tex2html_verbatim_mark>rows and m <tex2html_verbatim_mark>columns, where the rows go from east to west and the columns go from north to south. The orbiter determined the amount of yeyenum and bloggium in each cell. The astronauts will build a yeyenum refinement factory west of the rectangular area and a bloggium factory to the north. Your task is to design the conveyor belt system that will allow them to mine the largest amount of minerals.

There are two types of conveyor belts: the first moves minerals from east to west, the second moves minerals from south to north. In each cell you can build either type of conveyor belt, but you cannot build both of them in the same cell. If two conveyor belts of the same type are next to each other, then they can be connected. For example, the bloggium mined at a cell can be transported to the bloggium refinement factory via a series of south-north conveyor belts.

The minerals are very unstable, thus they have to be brought to the factories on a straight path without any turns. This means that if there is a south-north conveyor belt in a cell, but the cell north of it contains an east-west conveyor belt, then any mineral transported on the south-north conveyor beltwill be lost. The minerals mined in a particular cell have to be put on a conveyor belt immediately, in the same cell (thus they cannot start the transportation in an adjacent cell). Furthermore, any bloggium transported to the yeyenum refinement factory will be lost, and vice versa.

<tex2html_verbatim_mark>

Your program has to design a conveyor belt system that maximizes the total amount of minerals mined,i.e., the sum of the amount of yeyenum transported to the yeyenum refinery and the amount of bloggium transported to the bloggium refinery.

Input

The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1n500 <tex2html_verbatim_mark>of rows, and the number 1m500 <tex2html_verbatim_mark>of columns. The next n <tex2html_verbatim_mark>lines describe the amount of yeyenum that can be found in the cells. Each of these n <tex2html_verbatim_mark>lines contains m <tex2html_verbatim_mark>integers. The first line corresponds to the northernmost row; the first integer of each line corresponds to the westernmost cell of the row. The integers are between 0 and 1000. The next n <tex2html_verbatim_mark>lines describe in a similar fashion theamount of bloggium found in the cells.

The input is terminated by a block with n = m = 0 <tex2html_verbatim_mark>.

Output

For each test case, you have to output a single integer on a separate line: the maximum amount of mineralsthat can be mined.

Sample Input

4 4
0 0 10 9
1 3 10 0
4 2 1 3
1 1 20 0
10 0 0 0
1 1 1 30
0 0 5 5
5 10 10 10
0 0

Sample Output

98

dpw[row][col] = yey[row][col] + max(dpn[row - 1][col], dpw[row - 1][col]);
dpn[row][col] = blo[row][col] + max(dpn[row][col - 1], dpw[row][col - 1]);

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX = ;
int N, M;
int yey[MAX][MAX], blo[MAX][MAX];
int syey[MAX][MAX],sblo[MAX][MAX];
int dpw[MAX][MAX], dpn[MAX][MAX]; int main()
{
//freopen("sw.in","r",stdin);
while(~scanf("%d%d", &N, &M) && ( N + M)) {
memset(syey, , sizeof(yey));
memset(sblo, , sizeof(blo)); for(int i = ; i <= N; ++i) {
for(int j = ; j <= M; ++j) {
scanf("%d", &yey[i][j]);
yey[i][j] += yey[i][j - ];
}
} for(int i = ; i <= N; ++i) {
for(int j = ; j <= M; ++j) {
scanf("%d", &blo[i][j]);
blo[i][j] += blo[i - ][j];
}
} for(int row = ; row <= N; ++row) {
for(int col = ; col <= M; ++col) {
dpw[row][col] = yey[row][col] + max(dpn[row - ][col], dpw[row - ][col]);
dpn[row][col] = blo[row][col] + max(dpn[row][col - ], dpw[row][col - ]);
}
} printf("%d\n", max(dpw[N][M], dpn[N][M]));
}
//cout << "Hello world!" << endl;
return ;
}

LA 3350的更多相关文章

  1. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  2. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  3. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  4. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

  5. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  6. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  7. 获取在线人数 CNZZ 和 51.la

    string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...

  8. BNU OJ 33691 / LA 4817 Calculator JAVA大数

    留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同??? 数和运算符各开一个栈. 表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括 ...

  9. LA 3295 (计数 容斥原理) Counting Triangles

    如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单: ...

随机推荐

  1. 完全面向于初学者的Node.js指南

    新的上班时间是周二至周六,工作之余当然要坚持学习啦. 希望这篇文章能解决你这样一个问题:“我现在已经下载好Node.Js了,该做些什么呢?” 原文URL:http://blog.modulus.io/ ...

  2. eclipse集成maven

    1.工具下载: Eclipse4.2 jee版本(这里使用最新的Eclipse版本,3.7以上版本按照以下步骤都可以) 下载地址:http://www.eclipse.org/downloads/do ...

  3. C++类实现三维数组算法

    在学习北京大学教授的<程序设计实习 / Practice on Programming>中,遇到了一个习题,花了很长时间研究,现在分享出来: 课题地址:https://class.cour ...

  4. poj 2560 Freckles

    题目连接 http://poj.org/problem?id=2560 Freckles Description In an episode of the Dick Van Dyke show, li ...

  5. angularjs+nodejs+mongodb三件套

    说实话,自己对于web前段的认识并不是太深入,但是因为项目的需要,所以有的时候肯定会需要接触到web前段的知识点.说到web前端想必大家肯定会想到css+js+html,的确web前端的工作,从某总角 ...

  6. ios中怎么处理键盘挡住输入框

    //此前要遵循UITextFieldDelegate代理.并且设置该文本框为当前控制器的代理 //开始编辑的时候让整个view的高度网上移动 - (void)textFieldDidBeginEdit ...

  7. TableViewCell Swipe to Delete and More Button(like mail app in iOS7 or later)

    在iOS7系统的Mail App中TableViewCell的一个功能让我们做TableView的比较羡慕,就是滑动cell,右边出现了两个按钮,如下: 网上在github上有很多大牛用custom ...

  8. linux下操作

    一.没有正确安装GNOME电源管理器的默认配置 二.oracle启停 1. linux下启动oraclesu - oraclesqlplus /nologconn /as sysdbastartupe ...

  9. FastDFS安装配置

    FastDFS FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传.下载等服务 ...

  10. Android -- 获取汉字的首字母

    转换                                                                                             获取一个汉 ...