poj2948--Martian Mining(dp)
来源:互联网 发布:西安华信软件 编辑:程序博客网 时间:2024/06/06 02:08
Description
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 is terminated by a block with n = m = 0.
Output
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
Hint
给出每一个格子的矿的数量,只能向左或向右,并且道路只能是直线,所以每次只能加一行或一列
dp[i][j]代表从(1,1)到(i,j)可以得到的最大和,Map1向左Map1[i][j]第i行从第1个到第j个的和,Map2[i][j]代表第j列从第1个到第i个的和。
dp[i][j] = max( dp[i-1][j]+Map1[i][j],dp[i][j-1]+Map2[i][j] )
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
int Map1[510][510] , Map2[510][510];
int dp[510][510] ;
int n , m ;
int main()
{
int i , j , ans ;
while( scanf("%d %d", &n, &m) != EOF )
{
if( n == 0 && m == 0 ) break ;
ans = 0 ;
memset(dp,0,sizeof(dp)) ;
memset(Map1,0,sizeof(Map1)) ;
memset(Map2,0,sizeof(Map2)) ;
for(i = 1 ; i <= n ; i++)
for(j = 1 ; j <= m ; j++)
{
scanf("%d", &Map1[i][j]) ;
Map1[i][j] += Map1[i][j-1] ;
}
for(i = 1 ; i <= n ; i++)
for(j = 1 ; j <= m ; j++)
{
scanf("%d", &Map2[i][j]) ;
Map2[i][j] += Map2[i-1][j] ;
}
for(i = 1 ; i <= n ; i++)
{
for(j = 1 ; j <= m ; j++)
dp[i][j] = max( dp[i-1][j]+Map1[i][j],dp[i][j-1]+Map2[i][j] ) ;
}
printf("%d\n", dp[n][m] ) ;
}
return 0;
}
- poj2948 Martian Mining dp
- poj2948--Martian Mining(dp)
- Martian Mining poj2948
- POJ2948--Martian Mining
- poj2948 Martian Mining
- UVA1366-----Martian Mining------DP
- POJ 2948 Martian Mining DP
- Uva 1366 - Martian Mining dp
- UVa 1366 - Martian Mining (dp)
- uva 1366 - Martian Mining(dp)
- POJ 2948 Martian Mining(DP)
- Martian Mining - UVa 1366 dp
- UVa 1366 - Martian Mining (DP)
- UVA 1366 Martian Mining(dp)
- poj 2984Martian Mining(dp)
- poj 2948 -- Martian Mining(dp)
- UVA 1366 - Martian Mining(dp)
- UVaLive 3530 - Martian Mining (简单DP)
- 第三方下拉刷新快速集成
- poj 2054 Color a Tree 据说是贪心
- USACO6.4.3 Wisconsin Squares(wissqu)
- 深入分析 Java I/O 的工作机制
- JAVA中关于String的若干问题
- poj2948--Martian Mining(dp)
- mini2440 使用mdev创建设备节点问题
- 使用webservice操作强类型数据集时的注意事项
- HDU 1000 A+B Problem C/C++
- 动态调用动态语言--脚本API
- USACO6.5.1 All Latin Squares(latin)
- git的用法03
- 自学成才网站
- Android shape