POJ 2948 Martian Mining(DP)
题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿。
思路 :记忆化搜索。也可以用递推。
//
#include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; int yeye[][] ,blog[][] ;
int dp[][] ; int DP(int row,int col)
{
if(row < || col < ) return ;
else if(dp[row][col] != -) return dp[row][col] ;
else return dp[row][col] = max(DP(row-,col)+yeye[row][col],DP(row,col-)+blog[row][col]) ;
}
int main()
{
int n, m ;
while(~scanf("%d %d",&n,&m))
{
if(n == && m == ) break ;
for(int i = ; i < n ; i++)
for(int j = ; j < m ;j++)
scanf("%d",&yeye[i][j]) ;
for(int i = ; i < n ; i++)
for(int j = ; j < m ;j++)
scanf("%d",&blog[i][j]) ;
memset(dp,-,sizeof(dp)) ;
for(int i = ; i < n ; i++)
for(int j = ; j < m ; j++)
yeye[i][j] += yeye[i][j-] ;
for(int i = ; i < m ; i++)
for(int j = ; j < n ; j++)
blog[j][i] += blog[j-][i] ;
printf("%d\n",DP(n,m)) ;
}
return ;
}
POJ 2948 Martian Mining(DP)的更多相关文章
- (中等) POJ 2948 Martian Mining,DP。
Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- POJ 2948 Martian Mining
Martian Mining Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2251 Accepted: 1367 Descri ...
- POJ 3858 Hurry Plotter(DP)
Description A plotter is a vector graphics printing device that connects to a computer to print grap ...
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- POJ 2948 Martian Mining(DP)这是POJ第200道,居然没发现
题目链接 两种矿石,Y和B,Y只能从从右到左,B是从下到上,每个空格只能是上下或者左右,具体看图.求左端+上端最大值. 很容易发现如果想最优,分界线一定是不下降的,分界线上面全是往上,分界线下面都是往 ...
- poj 2948 Martian Mining (dp)
题目链接 完全自己想的,做了3个小时,刚开始一点思路没有,硬想了这么长时间,想了一个思路, 又修改了一下,提交本来没抱多大希望 居然1A了,感觉好激动..很高兴dp又有所长进. 题意: 一个row*c ...
- POJ 1260:Pearls(DP)
http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8 ...
- POJ 2192 :Zipper(DP)
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
随机推荐
- 《UNIX编程艺术》读书笔记
最近这段时间比较忙,利用业余时间看完了这本书.虽然书中讲到的很多例子都是上古文物,我没有用过,不过原理都是相通的,对我的启发很大.比如无所不在的KISS原则,实践中慢慢体会到的SPOT原则,无不产生共 ...
- Debug Intro
The ABAP Debugger is used tool to execute and analyze programs line by line. Using it we can check t ...
- [windows phone开发]新生助手的开发过程与体会二
上一讲咱们谈了新生助手主页的基本的设计,今天我们谈一谈关于展现实景地图时等动画的设计,即Storyboard的应用. 在Windows phone中,Storyboard类表示通过时间线控制动画,并为 ...
- c# 取得ip地址和网关
/// <summary> /// 得到本机IP /// </summary> private string GetLocalIP() { //本机IP地址 string st ...
- 匹配一级分类和二级分类 名字和url 里面有玄机
1:要匹配的html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
- JS中的this用法详解
随着对js的深入学习和使用,你会发现它里面包含了很多令人困惑的机制,比如对象.闭包.原型链继承等等,而这其中肯定包含令你现在或者曾经费解的this,如果你不把心一横,花点时间还真不明白这个this的用 ...
- 用golang启动一个daemon
用golang启动一个daemon package main import ( "fmt" "log" "os" "runtime ...
- Git客户端TortoiseGit(Windows系统)的使用方法
本文环境: 操作系统:Windows XP SP3 Git客户端:TortoiseGit-1.8.8.0-32bit 一.安装Git客户端 全部安装均采用默认! 1. 安装支撑软件 msysgit: ...
- html 布局;css3+jq 下拉菜单;table分页动态添加行;html5本地存储;简单易用的html框架
简单好用的html框架,预览图见最后: 源码: 1.页面布局使用table: table 嵌套 +iframe 布局: 2.下拉菜单为jq+css3 动画; css input 无边框,select下 ...
- hadoop集群默认配置和常用配置【转】
转自http://www.cnblogs.com/ggjucheng/archive/2012/04/17/2454590.html 获取默认配置 配置hadoop,主要是配置core-site.xm ...