1036 - A Refining Company
Time Limit: 3 second(s) Memory Limit: 32 MB

Its year 2200, planet Earth is out of resources and people are relying on the resources from other planets. There are several Refining Companies who collect these resources from other planets and bring them back to Earth. The task may sound simple, but in reality it's a challenging job. The resources are scattered and after collecting them, they have to be taken to a place where they can be refined. Since some minerals are extremely dangerous, the whole process should be done very carefully. A single tiny mistake can cause a massive explosion resulting in a huge loss.

You work in such a company who collects Uranium and Radium from planet Krypton. These minerals are used for generating powers. For simplicity you have divided planet Krypton into cells that form a matrix of m rows and n columns, where the rows go from east to west and the columns go from north to south. Your advanced mine detector has detected the approximate amount of Radium and Uranium in each cell. Your company has built two refining factories, one in West and the other in North. The factory in North is used to refine Radium and the factory in West is used to refine Uranium. 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 Radium mined at a cell can be transported to the Radium 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 belt will 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 Radium transported to the Uranium 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 Radium transported to the Radium refinery and the amount of Uranium to the Uranium refinery.

Input

Input starts with an integer T (≤ 10), denoting the number of test cases.

Each case begins with a blank line and two integers: m - the number of rows, and n - the number columns (1 ≤ m, n ≤ 500). The next m lines describe the amount of Uranium that can be found in the cells. Each of these m lines contains n 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 m lines describe in a similar fashion the amount of Radium found in the cells. Data set is huge, so use faster i/o methods.

Output

For each case of input you have to print the case number and the maximum amount of minerals you can collect.

Sample Input

Output for Sample Input

2

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

2 3

5 10 34

0 0 0

0 0 0

50 0 0

Case 1: 98

Case 2: 50

Note

Dataset is huge. Use faster I/O methods.

题意:给你两种方案,一种是从右往左的,一种是从下往上的,然后如果在某个点是向上的那么要一直到顶端,同理向左的,并且这写方案不能交叉,问最大能运多少。

dp[i][j]标是在大小为前i行前j列的最大能运输的,我们先处理所给的两个矩阵,第一个是右到左,我们处理没一行的前缀和,另一个是下到上,我们处理每一列的前缀和。

方程: dp[i][j] = max(dp[i-1][j] + __a[i][j],dp[i][j-1] + __b[i][j]);表示当前的位置要么向上要么向左。

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<stdlib.h>
4 #include<iostream>
5 #include<math.h>
6 #include<string.h>
7 #include<queue>
8 using namespace std;
9 typedef long long LL;
10 int a[600][600];
11 int b[600][600];
12 int dp[600][600];
13 int __a[600][600];
14 int __b[600][600];
15 int main(void)
16 {
17 int T;
18 scanf("%d",&T);
19 int __ca=0;
20 while(T--)
21 {
22 __ca++;
23 int n,m;
24 scanf("%d %d",&n,&m);
25 int i,j ;
26 for(i = 1; i <= n; i++)
27 {
28 for(j = 1; j <= m; j++)
29 {
30 scanf("%d",&a[i][j]);
31 }
32 }
33 for(i = 1; i <=n ; i++)
34 {
35 for(j = 1; j <= m; j++)
36 {
37 scanf("%d",&b[i][j]);
38 }
39 }
40 memset(__a,0,sizeof(__a));
41 memset(__b,0,sizeof(__b));
42 memset(dp,0,sizeof(dp));
43 for(i = 1; i <= n;i++)
44 {
45 for(j = 1; j <=m; j++)
46 __a[i][j]=__a[i][j-1]+a[i][j];
47 }
48 for( i = 1; i <= m; i++)
49 {
50 for(j = 1; j <= n; j++)
51 __b[j][i]=__b[j-1][i]+b[j][i];
52 }int maxx=0;
53 for(i = 1; i <= n ; i++)
54 {
55 for( j = 1; j <=m; j++)
56 {
57 dp[i][j] = max(dp[i-1][j] + __a[i][j],dp[i][j-1] + __b[i][j]);
58 }
59 }
60 printf("Case %d: %d\n",__ca,dp[n][m]);
61 }return 0;
62 }

1036 - A Refining Company的更多相关文章

  1. lightoj 1036 - A Refining Company(简单dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 ...

  2. Light OJ 1036 - A Refining Company

    题目大意: 一个m*n的矩阵,里面有两种矿物质铀和镭,现在要把铀和镭运送到指定位置.北边是炼镭厂,西边是了炼铀厂. 现在要建立传送带,传送带有两种,一种是从东到西,另一种是从南到北,传送带不能交叉,并 ...

  3. A Refining Company LightOJ - 1036

    A Refining Company LightOJ - 1036 描述好长啊... 题意:在m*n的矩阵上,每一格摆一个向上或者向左的传送带(不能同时摆,只能摆一个).同时,每一格有两种物资Uran ...

  4. LightOJ1036 A Refining Company(DP)

    题目大概说有一个n*m的格子地图,每个格子有铀或者镭矿.地图最北面的镭矿加工厂,最西面有铀矿加工厂,而要通过在格子里铺设由南向北(镭)或由东向西(铀)的轨道来送矿物到加工厂.一个格子只能铺设一种轨道, ...

  5. dp百题大过关(第一场)

    好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem    这 ...

  6. 【hihoCoder】1036 Trie图

    题目:http://hihocoder.com/problemset/problem/1036 给一个词典dict,词典中包含了一些单词words.要求判断给定的一个文本串text中是否包含这个字典中 ...

  7. Elasticsearch索引(company)_Centos下CURL增删改

    目录 返回目录:http://www.cnblogs.com/hanyinglong/p/5464604.html 1.Elasticsearch索引说明 a. 通过上面几篇博客已经将Elastics ...

  8. BZOJ 1036: [ZJOI2008]树的统计Count [树链剖分]【学习笔记】

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 14302  Solved: 5779[Submit ...

  9. Windows Locale Codes - Sortable list(具体一个语言里还可具体细分,中国是2052,法国是1036)

    Windows Locale Codes - Sortable list NOTE: Code page is an outdated method for character encoding, y ...

随机推荐

  1. 使用Mybatis出现的问题+配置优化+ResultMap

    一.可能出现的问题 1.Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: ...

  2. CPF C#跨平台UI框架发布安卓端预览版

    CPF的安卓端适配采用Xamarin的安卓绑定库,而不是Xamarin.Form.CPF和flutter差不多,完全由skia绘制,基本不依赖原生控件. 当前还只是预览版,不建议用在正式项目中. 可能 ...

  3. 巩固javaweb第十天

    巩固内容: HTML <meta> 元素 meta标签描述了一些基本的元数据. <meta> 标签提供了元数据.元数据也不显示在页面上,但会被浏览器解析. META 元素通常用 ...

  4. 《手把手教你》系列技巧篇(四十八)-java+ selenium自动化测试-判断元素是否可操作(详解教程)

    1.简介 webdriver有三种判断元素状态的方法,分别是isEnabled,isSelected 和 isDisplayed,其中isSelected在前面的内容中已经简单的介绍了,isSelec ...

  5. day01 前端bootstrap框架

    day01 django框架之bootstrap框架 今日内容概要 前端框架之bootstrap 该框架支持cv编写前端页面 利用socket模块编写一个简易版本的web框架 利用wsgiref模块编 ...

  6. Linux网络(网络模型和收发流程)

    网络模型 为了解决网络互联中异构设备的兼容性问题,并解耦复杂的网络包处理流程,国际标准化组织制定的开放式系统互联通信参考模型(Open System Interconnection Reference ...

  7. Linux 【复习巩固】

    目录 一.网络和服务 1.查看ip 2.查看主机名 配置 3.临时服务 1)基本语法(CentOS 6) 2)基本语法(CentOS 7) 3)示例 4.开机自启动服务 1)基本语法(CentOS 6 ...

  8. 08-认证(Authorization)

    这又是一个非常实用的功能,对我们做接口测试来说,经常要处理登录认证的情况 .如果不用这个Authorization其实也能解决认证的问题,无非就是把要认证的数据按照要求在指定位置传入参数即可.比如我们 ...

  9. LVS nat模型+dr模型

    nat模型 在 rs1 和 rs2  安装httpd  并配置测试页,启动 [root@rs1 ~]# yum install httpd -y[root@rs1 ~]# echo "thi ...

  10. java输入/输出流的基本知识

    通过流可以读写文件,流是一组有序列的数据序列,以先进先出方式发送信息的通道. 输入/输出流抽象类有两种:InputStream/OutputStream字节输入流和Reader/Writer字符输入流 ...