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&#233; &#224; la l&#233;g&#232;ret&#233; semblait &#234;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很像. 看到大神们写的博客,什么乱搞啊,随便统计一下,这真的让小白很为难,于是我决定用比较严格的语言来写这篇题解. 整体思路很简单: ...
随机推荐
-
Linux编译工具:gcc入门
1. 什么是gcc gcc的全称是GNU Compiler Collection,它是一个能够编译多种语言的编译器.最开始gcc是作为C语言的编译器(GNU C Compiler),现在除了c语言,还 ...
-
AngularJS控制器
AngularJS 控制器 控制 AngularJS 应用程序的数据,控制器是常规的 JavaScript 对象. 1. angular.module(name, [requires], [confi ...
-
Java学习笔记 02 String类、StringBuilder类、字符串格式化和正则表达式
一.String类一般字符串 声明字符串 >>String str 创建字符串 >>String(char a[])方法用于将一个字符数组创建为String对象 >> ...
-
《Out of control》阅读笔记(一)
Out Of Control 说实话,当初买这本书起源于知乎诸位学问人的推荐,脑子一热就买了.为了不浪费这几十块钱,细致了看完了前三章,买来一看才发现原来这本书居然跟计算机有很深刻的关系.其实更准确地 ...
-
mysql 自旋锁
自旋(spin)是一种通过不间断地测试来查看一个资源是否变为可用状态的等待操作,用于仅需要等待很短的时间等待所需资源的场景.使用自旋这种“空闲循环(busy-loop)”来完成资源等待的方式要比通过上 ...
-
ubuntu maven 安装 设置
http://blog.csdn.net/tiefanhe/article/details/9774189 1.安装 maven ,下载地址:http://maven.apache.org/downl ...
-
“盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&;&;源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】
黑白图像直方图 发布时间: 2017年7月9日 18:30 最后更新: 2017年7月10日 21:08 时间限制: 1000ms 内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...
-
利用jquery实现电商网站常用特效之:五星评分
这篇文章主要为大家详细介绍了基于jquery实现五星好评,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 在电商网站,我们经常会用到五星评分的功能,现在用jQuery实现一个简单的demo: 1.引 ...
-
FF中flash滚轮失效的解决方案
概述 在FF浏览器中有这样一个bug,就是当鼠标hover在flash区域的时候,滚轮会失效.原因是ff浏览器没有把滚轮事件嵌入到flash里面去.如果这个flash很小的话,比如直播的视频,会很容易 ...
-
day66 模板小结 [母板继承,块,组件]
小结: day65 1. 老师编辑功能写完 1. magic2函数 --> 用两层for循环解决 全栈8期之殇 问题 2. 模板语言 in 语法 {% if xx in xx_list %} { ...