题意:给定一个n*m的网格,每个格子里有A矿和B矿数量,A必须由右向左运,B只能从下向上运,中间不能间断,问最大总数量。

析:一个简单DP,dp[i][j] 表示 从 (0, 0) 到 (i, j) 最大人运输量。要么向左运输,要么向上运输,取最大值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 500 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int dp[maxn][maxn];
int a[maxn][maxn];
int b[maxn][maxn]; int main(){
while(scanf("%d %d", &n, &m) == 2 && n + m){
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j){
scanf("%d", &a[i][j]);
a[i][j] += a[i][j-1];
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j){
scanf("%d", &b[i][j]);
b[i][j] += b[i-1][j];
} memset(dp, 0, sizeof dp);
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
dp[i][j] = max(dp[i-1][j] + a[i][j], dp[i][j-1] + b[i][j]);
printf("%d\n", dp[n][m]);
}
return 0;
}

UVaLive 3530 Martian Mining (简单DP)的更多相关文章

  1. UVALive 3530 Martian Mining(贪心,dp)

    分析: 对于网格grid[i][j]如果放向上的管道,那么grid[i][k], k>j 就只能放向上的管道了. 那么定义dp[i][j]表示第i行,最后一个放向左的管道是j的最大总矿量. j ...

  2. POJ 2948 Martian Mining(DP)

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

  3. (中等) POJ 2948 Martian Mining,DP。

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

  4. 递推DP UVA 1366 Martian Mining

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

  5. POJ 2948 Martian Mining

    Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...

  6. UVA 1366 九 Martian Mining

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

  7. POJ 2498 Martian Mining

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

  8. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

随机推荐

  1. C#中的new和override(转)

    在衍生类中的方法上使用new和override关键字有何意义,可以通过一系列问题来找到答案.先看一段代码: 1 class Program 2 { 3 static void Main(string[ ...

  2. cocos2d-js添加百度appx的插屏广告(通过jsb反射机制)

    本来一直用的anysdk接入广告,结果从前几天开始,百度商店的审核总是通不过,结果一问才知道:要上传到百度商店就必须要用百度的appx(真的是各种坑,我们这些个人开发者迟早要被你们大公司玩死),没办法 ...

  3. OCR光学字符识别--STN-OCR 测试

    1.同文章中建议的使用ubuntu-python隔离环境,真的很好用 参照:http://blog.topspeedsnail.com/archives/5618启动虚拟环境:source env/b ...

  4. 【题解】HNOI2013比赛

    [题解][P3230 HNOI2013]比赛 将得分的序列化成样例给的那种表格,发现一行和一列是同时确定的.这个表格之前是正方形的,后来长宽都减去一,还是正方形.问题形式是递归的.这就启示我们可以把这 ...

  5. 3款Linux网络监视工具

    1 iftop: 如果你想看到现在你的带宽到底是哪些应用在使用,并且各个应用占据了多少带宽的时候,可以用iftop显示出来.使用的参数如下: -h                  display t ...

  6. linux日志系统介绍 —— syslog(),openlog(),closelog()

    函数使用介绍 这里面的三个函数openlog, syslog.closelog是一套系统日志写入接口.另外那个vsyslog和syslog功能一样,仅仅是參数格式不同.         通常.sysl ...

  7. Data Structure Binary Search Tree: Inorder Successor in Binary Search Tree

    struct node { int val; node *left; node *right; node *parent; node() : val(), left(NULL), right(NULL ...

  8. nodejs搭建简单的websocket服务端

    创建websocket服务端使用了nodejs-websocket ,首先要安装nodejs-websocket,在项目的目录下: npm install nodejs-websocket 1.搭建w ...

  9. BZOJ 4435 [Cerc2015]Juice Junctions 分治最小割+hash

    分治最小割的题目,要求n2. 之前用的n3的方法自然不能用了. 于是用hash,设hash[i][j]表示在最小割为i的时候,j是否与S联通. 看懂这个需要理解一下最小割树的构造. 这种题建议用EK写 ...

  10. 算法(Algorithms)第4版 练习 1.3.23 1.3.22

    1.3.23 When it comes time to update t.next, x.next is no longer the original node following x, but i ...