POJ 2948 Martian Mining

时间:2021-12-07 08:55:50
Martian Mining
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 2251 Accepted: 1367

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. 
POJ 2948 Martian Mining 
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.

Input

The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 ≤ n ≤ 500 of rows, and the number 1 ≤ m ≤ 500 of columns. The next n lines describe the amount of yeyenum that can be found in the cells. Each of these n lines contains m integers. The first line corresponds to the northernmost row; the first integer of each line corresponds to the westernmost cell of the row. The integers are between 0 and 1000. The next n lines describe in a similar fashion theamount of bloggium found in the cells.

The input is terminated by a block with n = m = 0.

Output

For each test case, you have to output a single integer on a separate line: the maximum amount of mineralsthat can be mined.

Sample Input

4 4
0 0 10 9
1 3 10 0
4 2 1 3
1 1 20 0
10 0 0 0
1 1 1 30
0 0 5 5
5 10 10 10
0 0

Sample Output

98

Hint

Huge input file, 'scanf' recommended to avoid TLE. 

Source

Central Europe 2005

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int yeye[555][555],blog[555][555],R,C,dp[555][555];

int getblog(int x,int y)
{
    int sum=0;
    for(int i=0;i<=x;i++)
        sum+=blog[y];
    return sum;
}

int getyeye(int x,int y)
{
    int sum=0;
    for(int i=0;i<=y;i++)
        sum+=yeye[x];
    return sum;
}

int main()
{
    while(scanf("%d%d",&R,&C)!=EOF)
    {
        if(R==0&&C==0) break;
        for(int i=1;i<=R;i++)
            for(int j=1;j<=C;j++)
                scanf("%d",&yeye[j]);
        for(int i=1;i<=R;i++)
            for(int j=1;j<=C;j++)
                scanf("%d",&blog[j]);
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=R;i++)
        {
            for(int j=1;j<=C;j++)
            {
                dp[j]=max(dp[i-1][j]+getyeye(i,j),dp[j-1]+getblog(i,j));
            }
        }
        printf("%d\n",dp[C]);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 2948 Martian Mining的更多相关文章

  1. &lpar;中等&rpar; POJ 2948 Martian Mining,DP。

    Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...

  2. POJ 2948 Martian Mining&lpar;DP&rpar;这是POJ第200道,居然没发现

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

  3. POJ 2948 Martian Mining(DP)

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

  4. poj 2948 Martian Mining &lpar;dp&rpar;

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

  5. POJ 2498 Martian Mining

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

  6. UVA 1366&Tab; 九 Martian Mining

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

  7. 递推DP UVA 1366 Martian Mining

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

  8. UVa 1366 - Martian Mining &lpar;dp&rpar;

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

  9. POJ 2948 DP

    一个row*col的矩阵,每一个格子内有两种矿yeyenum和bloggium,而且知道它们在每一个格子内的数量是多少.最北边有bloggium的收集站,最西边有 yeyenum 的收集站.如今要在这 ...

随机推荐

  1. 右键添加 CMD 命令提示符

    # 右键添加 CMD 命令提示符 当然是修改注册表   - 打开注册表编辑器(按下Win+R打开运行对话框,输入regedit),找到[HKEY_CLASSES_ROOT/Folder/shell] ...

  2. Linux终端更改提示符

    打开~/.bashrc可以看到命令提示的内容为:\u@\h\w\$ \u表示用户名,\h表示主机名,\w表示当前目录,\$表示命令提示符(普通用户$,超级用户#) 这个命令提示符有点长,很碍事,\u@ ...

  3. 多线程GCD

    经常使用:规避很多线程相关的复杂的逻辑 为什么会gcd?因为pthread和nsthread要求开发人员对线程相关的知识了解深入; 手动启动线程:加锁/解锁;造成很多隐患 --> 苹果公司给出了 ...

  4. Andrdoid中相应用程序的行为拦截实现方式之----从Java层进行拦截

    致谢: 感谢 简行之旅的这篇blog:http://blog.csdn.net/l173864930/article/details/38455951,这篇文章是參考这篇blog的进行一步一步操作的, ...

  5. 解析汽车B2C商城网站四种盈利模式

    汽车已成为家庭的日常用品,汽车的配套设施也成为销售的热点,汽车B2C电子商城为行业营销的新平台,汽车B2C电子商务网站盈利的模式是怎样的?创新的盈利模式才能在行业竞争中生存. 资讯产品一体模式 网站的 ...

  6. 关于Mysql下使用Dapper QueryFirstOrDefault的问题

    1.环境 MySql:5.7.20 Dapper:1.50.2 .Net:4.5 2.遇到的问题 在开发中我发现,使用Dapper查询数据时,第一次查询正确,第二次查询就差不出来,或者直接修改数据库后 ...

  7. 【笔记】两个根因分析方法:5WHY&amp&semi;10WHY

    什么是问题根因分析 根本原因分析(root cause analysis):通过调查和分析问题哪里出错.为什么出错,寻求防止差错事故再次发生的必要措施,从而提高服务安全和质量. 根因分析目标 问题(发 ...

  8. Cache-control使用Cache-control&colon;private学习笔记【转载】

    网页缓存由 HTTP消息头中的Cache-control控制,常见取值有private.no-cache.max-age.must- revalidate等,默认为private 其作用根据不同的重新 ...

  9. CentOS 7&period;4 64位安装配置MySQL8&period;0

    第一步:获取mysql YUM源 进入mysql官网获取RPM包下载地址 https://dev.mysql.com/downloads/repo/yum/   image.png 点击下载   im ...

  10. mongodb添加验证用户 删除用户

    1.创建用户 db.createUser( { user:<name_string>,                   #字符串 pwd:<password_string> ...