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. 【单源最短路模板】 poj 2387

    #include <cstdio> #include <iostream> #include <stdlib.h> #include <memory.h> ...

  2. cocos2d-lua SDK接入

    1.lua 调用Java函数 1.1 在java中创建一个静态函数(比如在org.cocos2dx.lua.AppActivity.java中)名为Login public static void m ...

  3. 从头到尾彻底解析Hash表算法

    作者:July.wuliming.pkuoliver 说明:本文分为三部分内容, 第一部分为一道百度面试题Top K算法的详解:第二部分为关于Hash表算法的详细阐述:第三部分为打造一个最快的Hash ...

  4. iframe子页面调用父页面javascript函数的方法

    1.iframe子页面调用 父页面js函数 子页面调用父页面函数只需要写上window.parent就可以了.比如调用a()函数,就写成: window.parent.a(); 2.iframe父页面 ...

  5. jenkins插件 build-name-setter

    #${BUILD_NUMBER}-${PROJECT_NAME}-${ENV,var="VARIABLENAME"}-${ENV,var="BUILD_USER" ...

  6. parseint和parsefloat总结number。隐形转换

    parseint:会认识一些字符+.-.空格,其他的就会截止譬如23hudhchauch结果为:23,对于boollen类型不能转换为1或是0. number:是对整体的转换.对true的转换为1. ...

  7. 使用U盘在Mac机上装win8.1系统

    1.首先要准备一个8G的U盘,用苹果机格式化为FAT格式.注意:U盘格式化之前要对U盘里的文件备份,U盘格式化后,里边的内容会清空. 2.下载原版win8.1系统,不要下载ghost版,http:// ...

  8. YII2 过滤器 filters

    使用过滤器 过滤器本质上是一类特殊的 行为,所以使用过滤器和 使用 行为一样. 可以在控制器类中覆盖它的 yii\base\Controller::behaviors() 方法来申明过滤器, 如下所示 ...

  9. alt+shift+j,添加日期、作者等

    在preference->Java->codestyle->codetemplates->commnets->type 可以编辑如: /** * @author ${us ...

  10. 简单的js实现网页时钟

    js实现时钟. <div id="clock"></div> <script type="text/javascript"> ...