LA 3350
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.
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的更多相关文章
- 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 ...
- 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 ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- Mac OS使用ll、la、l等ls的别名命令
在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- 获取在线人数 CNZZ 和 51.la
string Cookies = string.Empty; /// <summary> /// 获取在线人数 (51.la统计器) /// </summary> /// &l ...
- BNU OJ 33691 / LA 4817 Calculator JAVA大数
留着当个模板用,在BNU上AC,在LA上RE……可能是java的提交方式不同??? 数和运算符各开一个栈. 表达式从左到右扫一遍,将数存成大数,遇到数压在 数的栈,运算符压在 运算符的栈,每当遇到右括 ...
- LA 3295 (计数 容斥原理) Counting Triangles
如果用容斥原理递推的办法,这道题确实和LA 3720 Highway很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单: ...
随机推荐
- ios 总结
1 ocoa Touch Layer{ App Extensions https://developer.apple.com/library/ios/documentation/General/Con ...
- Ruby使用gets的错误:gets得到的有'\n',需要使用chomp去掉
gets方法得到的字符串包含一个“\n”回车符,所以我们需要继续使用chomp方法把"\n"回车符去掉
- C# 添加一个用户对文件或者文件夹的所有权限
private void ModifyFilePermission(string path, string user, FileType filetype) { if (filetype == Fil ...
- DB2查看用户表与指定用户表表结构
1.在dos中查看用户表 1.1查看表 DB2 LIST TABLES FOR USER 1.2 查看表结构 DB2 describe table A 2.在DB2连接工具中(这里以SQLdbx为例子 ...
- [Environment Build] Maven环境配置
1. 下载并解压maven文件 2. 在环境变量中配置一个JAVA_HOME的变量,指向你本地的JDK 3. 在系统变量中新建一个名为:MAVEN_HOME的变量,指向你的maven解压文件的bin目 ...
- Android-简单的sdcard文件浏览
功能:能够浏览手机里面的文件夹和文件,代码灰常简单 先看布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...
- android开发系列之回调函数
想必对于回调函数大家肯定不陌生,因为这是我们开发里面常用的代码技巧.我也就不废话了,让我们直接来看代码吧! public class TestCallback { public interface I ...
- go again
Introducation (1)How to organize go code (2)How to develope go package (3)How to use go tool How to ...
- Nginx Gzip 压缩配置
Nginx Gzip 压缩配置 随着nginx的发展,越来越多的网站使用nginx,因此nginx的优化变得越来越重要,今天我们来看看nginx的gzip压缩到底是怎么压缩的呢? gzip(GNU-Z ...
- [转]rpcndr.h和wtypes.h冲突Bug的解决方案
[转]rpcndr.h和wtypes.h冲突Bug的解决方案 http://blog.csdn.net/tzwh_86/article/details/9495133 rpcndr.h和wtypes. ...