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.

  题目就是给一个矩阵,然后问能够到最左边的所有直线和能够到最上边的所有直线经过的值的和。

  DP求解,dp[i][j]表示第i列向右的矩形所形成的最小值,其中j表示第i列的最后以↑的位置,然后从右向左推就好。

代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月20日 星期一 10时39分58秒
// File Name : 2948.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int N,M;
int C1[MaxN][MaxN];
int C2[MaxN][MaxN];
int dp[MaxN][MaxN]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int maxn; while(~scanf("%d %d",&N,&M) && N+M)
{
for(int i=;i<=N;++i)
for(int j=;j<=M;++j)
scanf("%d",&C1[i][j]); for(int i=;i<=N;++i)
for(int j=;j<=M;++j)
scanf("%d",&C2[i][j]); memset(dp,,sizeof(dp)); for(int i=;i<=M;++i)
{
for(int j=;j<=N;++j)
C2[j][i]+=C2[j-][i]; for(int j=N-;j>=;--j)
C1[j][i]+=C1[j+][i];
} for(int i=M;i>=;--i)
for(int j=;j<=N;++j)
{
maxn=; for(int k=j;k<=N;++k)
maxn=max(maxn,dp[i+][k]); dp[i][j]=maxn+C2[j][i]+C1[j+][i];
} maxn=; for(int i=;i<=N;++i)
maxn=max(maxn,dp[][i]); printf("%d\n",maxn);
} return ;
}

(中等) POJ 2948 Martian Mining,DP。的更多相关文章

  1. POJ 2948 Martian Mining(DP)这是POJ第200道,居然没发现

    题目链接 两种矿石,Y和B,Y只能从从右到左,B是从下到上,每个空格只能是上下或者左右,具体看图.求左端+上端最大值. 很容易发现如果想最优,分界线一定是不下降的,分界线上面全是往上,分界线下面都是往 ...

  2. poj 2948 Martian Mining (dp)

    题目链接 完全自己想的,做了3个小时,刚开始一点思路没有,硬想了这么长时间,想了一个思路, 又修改了一下,提交本来没抱多大希望 居然1A了,感觉好激动..很高兴dp又有所长进. 题意: 一个row*c ...

  3. POJ 2948 Martian Mining

    Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...

  4. POJ 2948 Martian Mining(DP)

    题目链接 题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿 ...

  5. POJ 2498 Martian Mining

    Martian Mining Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 2194   Accepted: 1326 De ...

  6. (中等) POJ 3034 Whac-a-Mole,DP。

    Description While visiting a traveling fun fair you suddenly have an urge to break the high score in ...

  7. UVa 1366 - Martian Mining (dp)

    本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 给出n*m网格中每个格子的A矿和B矿数量,A矿必须由右向左运输,B矿必须由下向上运输 ...

  8. 递推DP UVA 1366 Martian Mining

    题目传送门 /* 题意:抽象一点就是给两个矩阵,重叠的(就是两者选择其一),两种铺路:从右到左和从下到上,中途不能转弯, 到达边界后把沿途路上的权值相加求和使最大 DP:这是道递推题,首先我题目看了老 ...

  9. UVA 1366 九 Martian Mining

    Martian Mining Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

随机推荐

  1. asp之FSO大全

    <%Function ShowDriveInfo(strFolder)'显示磁盘信息'strRootFolder="/"'strDrivInfo=ShowDriveInfo( ...

  2. ListView控件的Insert、Edit和Delete功能(第一部分)

    摘自:http://blog.ashchan.com/archive/2007/08/28/listview-control-insert-edit-amp-delete-part-1aspx/ Li ...

  3. 【中国剩余定理】 poj 1006

    生理周期  简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...

  4. linux跨主机复制文件或文件夹

    复制文件基本格式:(本地到远程) scp 文件名 用户名@ip:文件全目录 如果是文件夹加上参数 -r scp -r 基础目录 用户名@ip:目录 栗子: scp local_file remote_ ...

  5. HttpSession详解

    HttpSession详解   session的机制 http是无状态的协议,客户每次读取web页面时,服务器都打开新的会话,而且服务器也不会自动维护客户的上下文信息,那么要怎么才能实现会话跟踪呢?s ...

  6. PARTITION BY 和 group by

    sum()   over   (PARTITION   BY   ...)   是一个分析函数.   他执行的效果跟普通的sum   ...group   by   ...不一样,它计算组中表达式的累 ...

  7. Spring的事务传播机制

    1.事务传播类型     新建事务 required required_new   - 挂起当前    非事务方式运行 supports not_supported  - 挂起当前 never    ...

  8. LINUX中磁盘挂载与卸除

    一.挂载格式与参数说明: 要将文件系统挂载到我们的 Linux 系统上,就要使用 mount 这个命令啦! 不过,这个命令真的是博大精深-粉难啦!我们学简单一点啊- ^_^ [root@www ~]# ...

  9. [学习opencv]高斯、中值、均值、双边滤波

    http://www.cnblogs.com/tiandsp/archive/2013/04/20/3031862.html [学习opencv]高斯.中值.均值.双边滤波 四种经典滤波算法,在ope ...

  10. cookies和session的优缺点

    具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案. Cookie的优缺点: 优点:极高的扩展性和可用性通过良好的编程,控制保存在cookie ...