POJ 2498 Martian Mining
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 2194 | Accepted: 1326 |
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 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
Hint
Source
容易的状态转换:
dp[i][j] = max(dp[i][j-1]+up[i][j],dp[i-1][j]+Left[i][j],dp[i-1][j-1]+Left[i][j-1]+up[i-1][j]+max(yey[i][j],blo[i][j]));
up[i][j] 还有left[i][j]可以预处理出来
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define N 510
using namespace std;
int yey[N][N],blo[N][N];
int up[N][N],Left[N][N],dp[N][N];
int main()
{
//freopen("data.in","r",stdin);
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
if(n==0&&m==0)
{
break;
}
memset(Left,0,sizeof(Left));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&yey[i][j]);
Left[i][j] = Left[i][j-1] + yey[i][j];
}
}
memset(up,0,sizeof(up));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&blo[i][j]);
up[i][j] = up[i-1][j] + blo[i][j];
}
}
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int k = max(dp[i][j-1]+up[i][j],dp[i-1][j]+Left[i][j]);
k = max(k,dp[i-1][j-1]+Left[i][j-1]+up[i-1][j]+max(yey[i][j],blo[i][j]));
dp[i][j] = max(k,dp[i][j]);
}
}
printf("%d\n",dp[n][m]);
}
return 0;
}
POJ 2498 Martian Mining的更多相关文章
- POJ 2948 Martian Mining
Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...
- POJ 2948 Martian Mining(DP)这是POJ第200道,居然没发现
题目链接 两种矿石,Y和B,Y只能从从右到左,B是从下到上,每个空格只能是上下或者左右,具体看图.求左端+上端最大值. 很容易发现如果想最优,分界线一定是不下降的,分界线上面全是往上,分界线下面都是往 ...
- POJ 2948 Martian Mining(DP)
题目链接 题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿 ...
- poj 2948 Martian Mining (dp)
题目链接 完全自己想的,做了3个小时,刚开始一点思路没有,硬想了这么长时间,想了一个思路, 又修改了一下,提交本来没抱多大希望 居然1A了,感觉好激动..很高兴dp又有所长进. 题意: 一个row*c ...
- (中等) POJ 2948 Martian Mining,DP。
Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...
- UVA 1366 九 Martian Mining
Martian Mining Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- 递推DP UVA 1366 Martian Mining
题目传送门 /* 题意:抽象一点就是给两个矩阵,重叠的(就是两者选择其一),两种铺路:从右到左和从下到上,中途不能转弯, 到达边界后把沿途路上的权值相加求和使最大 DP:这是道递推题,首先我题目看了老 ...
- poj 2498 动态规划
思路:简单动态规划 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- UVa 1366 - Martian Mining (dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 给出n*m网格中每个格子的A矿和B矿数量,A矿必须由右向左运输,B矿必须由下向上运输 ...
随机推荐
- OC中两种单例实现方式
OC中两种单例实现方式 写在前面 前两天探索了一下C++ 的单例,领悟深刻了许多.今天来看看OC中的单例又是怎么回事.查看相关资料,发现在OC中一般有两种实现单例的方式,一种方式是跟C++ 中类似的常 ...
- redo文件一
redo log files and redo log buffer redo log files的作用的是确保数据库崩溃之后能正确的恢复数据库,恢复数据库到一,致性的状态 redo log file ...
- Motan:目录结构
motan是由maven管理的,在最外层的pom.xml中可以看出这个项目有多个模块组成. <modules> <module>motan-core</module> ...
- 超简单fedora20(linux)下JDK1.8的安装
(博客园-番茄酱原创) 去官网下载linux版本的jdk,如果你的fedora是64位,就选择64位的jdk,jdk-8u20-linux-x64.tar.gz. 将下载好的jdk解压到当前目录下,解 ...
- Android与Mysql服务器通信
需求:在手机端读取蓝牙传输过来的数据,然后发送到mysql 安卓前期版本可以直接使用mysql connector, 现在只能通过访问url传递数据了. 服务器端写php脚本,接受发送过来的url请求 ...
- Java设计模式系列之单例模式
单例模式的定义 一个类有且仅有一个实例,并且自行实例化向整个系统提供.比如,多程序读取一个配置文件时,建议配置文件时,建议配置文件封装成对象.会方便操作其中的数据,又要保证多个程序读到的是同一个配置文 ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- HDU1398Square Coins(母函数)
母函数介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数) #include<iostream> #include<stdio.h> ...
- CodeForces 706B Interesting drink (二分查找)
题意:给定 n 个数,然后有 m 个询问,每个询问一个数,问你小于等于这个数的数有多少个. 析:其实很简单么,先排序,然后十分查找,so easy. 代码如下: #pragma comment(lin ...
- 《UNIX环境高级编程》笔记--更改用户ID和组ID
在unix系统中,特权是基于用户和组ID的,当程序需要增加特权,或需要访问当前并不允许访问的资源时,我们需要更换自己 用户ID或组ID,使的新ID具有合适的特权或访问权限.与此类似,当程序需要降低其特 ...