poj 2948 Martian Mining
来源:互联网 发布:淘宝搜索关键字看福利 编辑:程序博客网 时间:2024/05/08 12:20
http://poj.org/problem?id=2948
Description
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 rows and m 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.
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 rows and m 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 1 ≤ n ≤ 500 of rows, and the number 1 ≤ m ≤ 500 of columns. The next n lines describe the amount of yeyenum that can be found in the cells. Each of these n lines contains m 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 lines describe in a similar fashion theamount of bloggium found in the cells.
The input is terminated by a block with n = m = 0.
The input is terminated by a block with n = m = 0.
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 40 0 10 91 3 10 04 2 1 3 1 1 20 010 0 0 01 1 1 300 0 5 55 10 10 100 0
Sample Output
98题目大意:在一个矿物质的采集地,有两种矿物质,一种是yeyenum,一种是bloggium,bloggium往北运输,yeyenum往西运输,在一个矩形的区域内有这些物质,这个区域分成单元格(如图所示),每个单元格同时存在这两种物质,但是数量是不一样的。现在将他们运输到北面或西面,要建设传送带,传送带的方向是不能改变的,即只能是往北,或者只能往西,不能有拐点,如图所示。问如何建设传送带运输这两种物质能保证他们的总和最大(如果传送方向为北,则只能运输bloggium,往西只能运输(yeyenum),最大是多少
基本思路:
可以看出只要位置(x,y)确定了方向,那么(0-x)或(0-y)就确定了方向。记录dp[x][y]表示从左上角走到(x,y)位置时取得的最大的运输量,那么有dp[x][y]=max(ye[x][y]+dp[i-1][j],blo[x][y]+dp[i][j-1]),其中ye[x][y]表示从(x,0)到(x,y)的yeyenum矿物质的总量,blo[x][y]同理。
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;int dp[505][505];int ye[505][505];int blo[505][505];int main(){ int n,m; while(scanf("%d%d",&n,&m)) { int x; if(n==0&&m==0)break; memset(dp,0,sizeof(dp)); memset(ye,0,sizeof(ye)); memset(blo,0,sizeof(blo)); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%d",&x); ye[i][j]+=ye[i][j-1]+x; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { scanf("%d",&x); blo[i][j]+=blo[i-1][j]+x; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { dp[i][j]=max(dp[i][j-1]+blo[i][j],dp[i-1][j]+ye[i][j]); } } printf("%d\n",dp[n][m]); } return 0;}
0 0
- Poj 2948 Martian Mining
- POJ-2948-Martian Mining
- POJ 2948 Martian Mining
- POJ 2948 Martian Mining
- poj 2948 Martian Mining
- poj 2948 Martian Mining
- POJ 2948 Martian Mining
- POJ 2948 Martian Mining DP
- POJ 2948 Martian Mining(DP)
- poj 2948 -- Martian Mining(dp)
- [poj 2948] Martian Mining 棋盘型DP
- POJ 2498 Martian Mining
- poj 2984Martian Mining(dp)
- poj 2948 Martian Mining dp
- POJ 2948 Martian Mining(简单的二维dp)
- 【poj 2948】Martian Mining 题意&题解&代码(C++)
- pku2948 Martian Mining
- Martian Mining poj2948
- 位操作基础篇之位操作全面总结
- 居中布局
- Linux 处理目录以及文件的相关命令
- java系列笔记---正则表达式(1)常用符号
- shellinabox的使用
- poj 2948 Martian Mining
- Android在非Activity里边使用startActivity的异常解决办法
- QLServer 2008以上误操作数据库恢复方法——日志尾部备份
- 小程序中的单位
- 前端-有关form表单
- .NET第二章 进制转换
- Ubuntu 输入正确的密码后,黑屏一闪,重新返回到登陆界面问题解决
- 汇编语言(王爽)——第三次上机
- mysql 整理之mysql 参数关注与优化