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. AU3脚本 记录

    编译程序使用自定义图标: #AutoIt3Wrapper_Icon=自定义图标地址 打开指定的网址:(也可以指定其他浏览器exe) Run(@ProgramFilesDir & "\ ...

  2. Break on _NSLockError() to debug.

    *** -[NSCondition dealloc]: condition (<NSCondition: 0x1039a450> '(null)') deallocated while s ...

  3. angular.js之路由的选择

    在一个单页面中,我们可以添加多个模块,使得网页只在需要的时候加载这个模块.模块的切换大致上可以代替网页的切换,于是,我们便可以通过模块的切换实现网页的切换,这个切换是按需加载的. 乍一看非常普通的东西 ...

  4. jQuery 数据滚动(上下)

    setInterval(function() { jq('.sjbg02 li:first').animate({ 'height': '0', 'opacity': '0' }, 'slow', f ...

  5. w3chtml页面和css书写规范

    http://www.cnblogs.com/Wenwang/archive/2011/09/07/2169881.html

  6. Windows应用程序要点

    一个完整的Windows应用程序除了WinMain函数外,还包含用于处理用户动作和窗口消息的窗口函数.  Windows应用程序具有的一些特性: 消息驱动机制 图形设备接口(GDI) 基于资源的程序设 ...

  7. Nginx反向代理使用【转载】

    最近工作中经常使用nginx,为了能够更好的使用nginx,我搜罗了很多nginx相关的技术文章来读,所以才有了下面以下内容.在此,为文中引用到和参考到的文章提供者表示感谢.如文中相关内容有错误,也欢 ...

  8. 【转】php缓冲 output_buffering和ob_start

    原文: http://blog.csdn.net/21aspnet/article/details/7389427 php缓冲 output_buffering和ob_start buffer buf ...

  9. Redis hash 类型及操作

    原文:http://blog.sina.com.cn/s/blog_5f044a4d0102v01k.html Redis hash是一个string类型的field和value的映射表.它的添加.删 ...

  10. android脚步---数字时钟和模拟时钟

    时钟UI组件是两个非常简单的组件,分为Digitalclock  和Analogclock, main.xml文件,书中程序有问题,加了两个组件,一个Button和一个<Chronometer ...