博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(中等) POJ 2948 Martian Mining,DP。
阅读量:4357 次
发布时间:2019-06-07

本文共 4053 字,大约阅读时间需要 13 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int MaxN=510;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=1;i<=N;++i) for(int j=1;j<=M;++j) scanf("%d",&C1[i][j]); for(int i=1;i<=N;++i) for(int j=1;j<=M;++j) scanf("%d",&C2[i][j]); memset(dp,0,sizeof(dp)); for(int i=1;i<=M;++i) { for(int j=2;j<=N;++j) C2[j][i]+=C2[j-1][i]; for(int j=N-1;j>=1;--j) C1[j][i]+=C1[j+1][i]; } for(int i=M;i>=1;--i) for(int j=0;j<=N;++j) { maxn=0; for(int k=j;k<=N;++k) maxn=max(maxn,dp[i+1][k]); dp[i][j]=maxn+C2[j][i]+C1[j+1][i]; } maxn=0; for(int i=0;i<=N;++i) maxn=max(maxn,dp[1][i]); printf("%d\n",maxn); } return 0;}
View Code

 

转载于:https://www.cnblogs.com/whywhy/p/4660839.html

你可能感兴趣的文章
csdn肿么了,这两天写的博文都是待审核
查看>>
windows下cocos2dx3.0开发环境及Android编译环境搭建
查看>>
BW连接数据库
查看>>
登录之后更新导航
查看>>
spring 的单例模式
查看>>
Python学习手册
查看>>
完整的系统帮助类Utils
查看>>
Python 的语言特性
查看>>
使用PowerShell批量注册DLL到GAC
查看>>
微软职位内部推荐-Senior Development Engineer
查看>>
创建数据库的方法
查看>>
递归算法
查看>>
关于java中sendRedirect,forward和include区别
查看>>
在红帽RHEL7.0里配置网卡的四种方法
查看>>
LeetCode--二分查找相关算法
查看>>
RobotFramework自动化测试框架系统关键字之断言
查看>>
《Node.js In Action》笔记之流程控制
查看>>
通俗易懂云计算
查看>>
zigbee首次开通
查看>>
Hibernate查询-hql
查看>>