LA 3350

时间:2023-01-09 14:01:10

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.

LA 3350<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 1LA 3350nLA 3350500 <tex2html_verbatim_mark>of rows, and the number 1LA 3350mLA 3350500 <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&&num;233&semi; &&num;224&semi; la l&&num;233&semi;g&&num;232&semi;ret&&num;233&semi; semblait &&num;234&semi;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中的动态库和静态库&lpar;&period;a&sol;&period;la&sol;&period;so&sol;&period;o&rpar;

    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. &period;Uva&amp&semi;LA部分题目代码

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

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

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

  8. BNU OJ 33691 &sol; LA 4817 Calculator JAVA大数

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

  9. LA 3295 &lpar;计数 容斥原理&rpar; Counting Triangles

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

随机推荐

  1. Linux编译工具:gcc入门

    1. 什么是gcc gcc的全称是GNU Compiler Collection,它是一个能够编译多种语言的编译器.最开始gcc是作为C语言的编译器(GNU C Compiler),现在除了c语言,还 ...

  2. AngularJS控制器

    AngularJS 控制器 控制 AngularJS 应用程序的数据,控制器是常规的 JavaScript 对象. 1. angular.module(name, [requires], [confi ...

  3. Java学习笔记 02 String类、StringBuilder类、字符串格式化和正则表达式

    一.String类一般字符串 声明字符串 >>String str 创建字符串 >>String(char a[])方法用于将一个字符数组创建为String对象 >&gt ...

  4. 《Out of control》阅读笔记(一)

    Out Of Control 说实话,当初买这本书起源于知乎诸位学问人的推荐,脑子一热就买了.为了不浪费这几十块钱,细致了看完了前三章,买来一看才发现原来这本书居然跟计算机有很深刻的关系.其实更准确地 ...

  5. mysql 自旋锁

    自旋(spin)是一种通过不间断地测试来查看一个资源是否变为可用状态的等待操作,用于仅需要等待很短的时间等待所需资源的场景.使用自旋这种“空闲循环(busy-loop)”来完成资源等待的方式要比通过上 ...

  6. ubuntu maven 安装 设置

    http://blog.csdn.net/tiefanhe/article/details/9774189 1.安装 maven ,下载地址:http://maven.apache.org/downl ...

  7. &OpenCurlyDoubleQuote;盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&amp&semi;&amp&semi;源码【A&comma;水&comma;B&comma;水&comma;C&comma;水&comma;D&comma;快速幂&comma;E&comma;优先队列&comma;F&comma;暴力&comma;G&comma;贪心&plus;排序&comma;H&comma;STL乱搞&comma;I&comma;尼姆博弈&comma;J&comma;差分dp&comma;K&comma;二分&plus;排序&comma;L&comma;矩阵快速幂&comma;M&comma;线段树区间更新&plus;Lazy思想&comma;N&comma;超级快速幂&plus;扩展欧里几德&comma;O&comma;BFS】

    黑白图像直方图 发布时间: 2017年7月9日 18:30   最后更新: 2017年7月10日 21:08   时间限制: 1000ms   内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...

  8. 利用jquery实现电商网站常用特效之:五星评分

    这篇文章主要为大家详细介绍了基于jquery实现五星好评,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 在电商网站,我们经常会用到五星评分的功能,现在用jQuery实现一个简单的demo: 1.引 ...

  9. FF中flash滚轮失效的解决方案

    概述 在FF浏览器中有这样一个bug,就是当鼠标hover在flash区域的时候,滚轮会失效.原因是ff浏览器没有把滚轮事件嵌入到flash里面去.如果这个flash很小的话,比如直播的视频,会很容易 ...

  10. day66 模板小结 &lbrack;母板继承&comma;块&comma;组件&rsqb;

    小结: day65 1. 老师编辑功能写完 1. magic2函数 --> 用两层for循环解决 全栈8期之殇 问题 2. 模板语言 in 语法 {% if xx in xx_list %} { ...