poj 2948 Martian Mining (dp)
完全自己想的,做了3个小时,刚开始一点思路没有,硬想了这么长时间,想了一个思路,
又修改了一下,提交本来没抱多大希望 居然1A了,感觉好激动。。很高兴dp又有所长进。
题意: 一个row*col的矩阵,每个格子内有两种矿yeyenum和bloggium,并且知道它们在每个
格子内的数量是多少。最北边有bloggium的收集站,最西边有 yeyenum 的收集站。
现在要在这些格子上面安装向北或者向西的传送带(每个格子自能装一种)。问最多能采到多少矿。
传送带只能直着走,不可弯曲,不能交叉。
分析:做题的时候一直在想状态转移 之间的关系,后来发现应该从左上角开始看起,每一个非零值的
格子,都要有一个传送的方向,因为是从上往下,从左往右的,所以前面的已经计算过了,所以方程
为d[i][j] = max(d[i-1][j]+ye[i][j], d[i][j-1]+bl[i][j]);
ye[i][j]表示从i行0列 到 i行j列的ye值, bl类似。
样例解释:
^ | ^ | ||
< | < | < | ^ |
< | < | < | ^ |
< | < | < | ^ |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const int maxn = + ;
int n, m, d[maxn][maxn], ye[maxn][maxn], bl[maxn][maxn]; int main()
{
int i, j, a;
while(~scanf("%d%d", &n, &m))
{
if(n== && m==) break;
memset(d, , sizeof(d));
memset(ye, , sizeof(ye));
memset(bl, , sizeof(bl));
for(i = ; i <= n; i++)
for(j = ; j <= m; j++)
{
scanf("%d", &a);
ye[i][j] = ye[i][j-] + a;
}
for(i = ; i <= n; i++)
for(j = ; j <= m; j++)
{
scanf("%d", &a);
bl[i][j] = bl[i-][j] + a;
}
for(i = ; i <= n; i++)
for(j = ; j <= m; j++)
d[i][j] = max(d[i-][j]+ye[i][j], d[i][j-]+bl[i][j]); printf("%d\n", d[n][m]);
}
return ;
}
poj 2948 Martian Mining (dp)的更多相关文章
- POJ 2948 Martian Mining(DP)这是POJ第200道,居然没发现
题目链接 两种矿石,Y和B,Y只能从从右到左,B是从下到上,每个空格只能是上下或者左右,具体看图.求左端+上端最大值. 很容易发现如果想最优,分界线一定是不下降的,分界线上面全是往上,分界线下面都是往 ...
- POJ 2948 Martian Mining
Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...
- (中等) POJ 2948 Martian Mining,DP。
Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...
- POJ 2948 Martian Mining(DP)
题目链接 题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿 ...
- POJ 2498 Martian Mining
Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2194 Accepted: 1326 De ...
- UVa 1366 - Martian Mining (dp)
本文出自 http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题目大意 给出n*m网格中每个格子的A矿和B矿数量,A矿必须由右向左运输,B矿必须由下向上运输 ...
- 递推DP UVA 1366 Martian Mining
题目传送门 /* 题意:抽象一点就是给两个矩阵,重叠的(就是两者选择其一),两种铺路:从右到左和从下到上,中途不能转弯, 到达边界后把沿途路上的权值相加求和使最大 DP:这是道递推题,首先我题目看了老 ...
- UVA 1366 九 Martian Mining
Martian Mining Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Sta ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
随机推荐
- Very large tabs in eclipse panes on Ubuntu
http://stackoverflow.com/questions/11805784/very-large-tabs-in-eclipse-panes-on-ubuntu ou can edit E ...
- Jquery 固定悬浮层以及固定表头
/* =========================================================== * jquery.autofix_anything.js v1 * === ...
- spring mvc 学习笔记【1】---前言
扎扎实实地掌握好技术 ----------------------------------------------------------------------------------------- ...
- 2877: [Noi2012]魔幻棋盘 - BZOJ
DescriptionInput 第一行为两个正整数N,M,表示棋盘的大小. 第二行为两个正整数X,Y,表示棋盘守护者的位置. 第三行仅有一个正整数T,表示棋盘守护者将进行次操作. 接下来N行,每行有 ...
- switch..case函数的基础使用一
基本作用:switch中的参数与case的值进行比对,相等则进入case. JDK1.7 switch支持int.Integer.String类型 package com.my.test; impor ...
- MyEclipse 2015 Stable 1.0下载安装破解日志
前言 这2天下载了许多myeclipse版本,基本上是14/15版本的,各种破解均告以失败,这次下载了贴吧一个吧友提供的版本,现已破解.破解结果现不好说--目前已装SVN,根据经验,只有等待一定时间验 ...
- MVC3 Model Binding验证方式
1.使用ModelState在Action中进行验证 [HttpPost] public ViewResult MakeBooking(Appointment appt) { if (string.I ...
- java split函数 对空的处理
String str = "5,6,55,66,,,,@"; String[] chk_deep = str.split("@"); System.out.pr ...
- 设置go语言语法高亮
1. 将$GOROOT/misc/vim/go.vim文件拷贝到-/.vim/syntax/目录下 2. 添加下面代码到~/.vimrc文件中 let mysyntaxfile = "XXX ...
- unity3d GameObject.Find 严格区分大小写的
GameObject.Find 查找 static function Find (name : string) : GameObject Description描述 Finds a game obje ...