Medium POJ 2948 Martian MINING,DP.

Source: Internet
Author: User

Description

The NASA Space Center, Houston, is less than, miles from San Antonio, Texas (the site of the ACM finals this year). This was the place where the astronauts was trained for Mission Seven dwarfs, and the next giant leap in space exploration. The Mars Odyssey program revealed, the surface of Mars is very rich in yeyenum and Bloggium. These minerals is important ingredients for certain revolutionary new medicines, but they is 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 the Mars, that's rich in minerals. The area was divided into cells the form a matrix of n rows and M columns, where the rows go from east to west and the COL Umns go. The orbiter determined the amount of yeyenum and bloggium in each cell. The astronauts would 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 would allow them to mine the largest amount of minerals.

There is types of conveyor belts:the first moves minerals from east to west, the second moves minerals from North. In each cell you can build either type of conveyor belt, but you cannot build both of them in the same cell. If the conveyor belts of the same type is next to all other and 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-nort H Conveyor belts.

The minerals is very unstable, thus they has to being brought to the factories in a straight path without any turns. This means if there are a South-north conveyor belt in a cell, but the cell north of it contains an east-west conveyor Belt mineral transported on the South-north conveyor Beltwill is lost. The minerals mined in a particular cell has a to is 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 would be lost, and vice versa.

Your program have to design a conveyor belt system this maximizes the total amount of minerals mined,i.e., the sum of the A Mount of Yeyenum transported to the Yeyenum refinery and the amount of bloggium transported to the Bloggium refinery.

The title is to give a matrix, and then ask to be able to the left of all the straight line and can go to the top of all the lines passing the value of the.

DP Solver, Dp[i][j] represents the smallest value formed by a rectangle to the right of the column I, where J represents the position of the last ↑ of column I, and then pushes from right to left.

The code is as follows:

//The ━━━━━━ of gods and Beasts ━━━━━━//┏┓┏┓//┏┛┻━━━━━━━┛┻┓//┃┃//┃━┃//████━████┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//┃┃//┃┃//┃┗━━━┓//┃┣┓//┃┏┛//┗┓┓┏━━━━━┳┓┏┛//┃┫┫┃┫┫//┗┻┛┗┻┛////━━━━━━ Feel the ━━━━━━ of Meng Meng//author:whywhy//Created time:2015 July 20 Monday 10:39 58 seconds//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 namespacestd;Const intmaxn=510;intn,m;intC1[MAXN][MAXN];intC2[MAXN][MAXN];intDP[MAXN][MAXN];intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);    intMAXN;  while(~SCANF ("%d%d", &n,&m) && n+M) { for(intI=1; i<=n;++i) for(intj=1; j<=m;++j) scanf ("%d",&C1[i][j]);  for(intI=1; i<=n;++i) for(intj=1; j<=m;++j) scanf ("%d",&C2[i][j]); Memset (DP,0,sizeof(DP));  for(intI=1; i<=m;++i) { for(intj=2; j<=n;++j) C2[j][i]+=c2[j-1][i];  for(inti=m-1; j>=1;--j) C1[j][i]+=c1[j+1][i]; }         for(inti=m;i>=1;--i) for(intj=0; j<=n;++j) {MAXN=0;  for(intk=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(intI=0; i<=n;++i) MAXN=max (maxn,dp[1][i]); printf ("%d\n", MAXN); }        return 0;}
View Code

Medium POJ 2948 Martian MINING,DP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.