LightOJ 1036 - A Refining Company(dp)
来源:互联网 发布:iphonex监控预约软件 编辑:程序博客网 时间:2024/04/30 07:15
题意:
在一个n∗m(n,m<=500)的地图里有R矿和U矿,当你在某个点(x,y),可以建造一个只能向西或者向北挖取矿石的履带车
R矿石只能被向北移动的履带车挖取,U矿石只能被向西移动的履带车挖取,并且履带车不能交叉
$给出你每个地点的R矿和U矿的数量, 求最大运送的矿石数目(履带车会一直走到边界)
分析:
当你位于(x, y)时, 你只有两个操作:
1)建立一个向北运输的履带车, 挖一路上的R矿石
2)建立一个想西运输的履带车, 挖一路上的U矿石
考虑dp[i][j]:=(1,1)→(i,j)这个矩形区域所能运送的最大矿石数量
预处理出(i,j)这点向北运送的R矿石的前缀和,向西的U矿石的前缀和
转移对于(i,j),向北dp[i][j−1]+sumR(i,j),向西dp[i−1][j]+sumU(i,j)
dp[i][j]=max(dp[i][j−1]+sumR(i,j),dp[i−1][j]+sumU(i,j))
ans=dp[n][m]
代码:
//// Created by TaoSama on 2015-11-13// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, m, a[505][505], b[505][505], dp[505][505];int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int t; scanf("%d", &t); int kase = 0; while(t--) { scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) { //U to west for(int j = 1; j <= m; ++j) { int x; scanf("%d", &x); a[i][j] = a[i][j - 1] + x; } } for(int i = 1; i <= n; ++i) { //R to north for(int j = 1; j <= m; ++j) { int x; scanf("%d", &x); b[i][j] = b[i - 1][j] + x; } } memset(dp, 0, sizeof dp); //(1,1)~(i,j) rectangle 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("Case %d: %d\n", ++kase, dp[n][m]); } return 0;}
0 0
- lightoj 1036 - A Refining Company (dp)
- LightOJ 1036 - A Refining Company(dp)
- LightOJ 1036 - A Refining Company(dp)
- LightOJ 1036 - A Refining Company(DP)
- lightoj 1036 - A Refining Company DP
- lightoj - 1036 - A Refining Company / dp
- lightoj 1036 - A Refining Company
- Light OJ 1036A Refining Company (DP)
- A - A Refining Company
- Light OJ 1036A Refining Company
- A Refining Company
- LightOJ - 1180 Software Company(二分+dp)
- lightoj 1180 - Software Company 二分+DP
- LightOJ - 1039 A Toy Company(BFS)
- LightOj 1221 - Travel Company(spfa判负环)
- Software Company LightOJ
- Lightoj 1036 DP(记忆化搜索)
- LightOJ 1221 Travel Company(贝尔曼最短路判负环)
- IOS,Tabbar,设置全局导航UINavigationBar
- MyEclipse强制退出后闪退进不去workbench
- 第十二章 与Spring集成
- MATLAB和C/C++混合编程实现图像处理(一)
- 创建网页版UFT脚本技术点
- LightOJ 1036 - A Refining Company(dp)
- 【Android】Android项目中R文件找不到怎么处理?
- 第十三章 RememberMe
- Codeforces 597C Subsequences 【树状数组优化DP】
- 第十四章 SSL
- 遍历一个文件夹下面的文件(半原创)
- 在64位Ubuntu 14.04 LTS 中安装praat
- [leetcode 19] Remove Nth Node From End of List
- 第十五章 单点登录