POJ1088(dp)
滑雪
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 91574 | Accepted: 34573 |
Description
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。
Input
Output
Sample Input
5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Sample Output
25 dp,用记忆化搜索
//2016.8.5
//POJ1088
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int n, m;
int h[][];
int dp[][];
int dx[] = {, , , -};
int dy[] = {, , -, }; int dfs(int x, int y)
{
if(dp[x][y])return dp[x][y];//记忆化搜索
int tmp, maxl = ;
for(int i = ; i < ; i++)
{
int nx = x+dx[i];
int ny = y+dy[i];
if(nx>=&&nx<n&&ny>=&&ny<m&&h[nx][ny]<h[x][y])
{
tmp = dfs(nx, ny);
if(tmp>maxl)maxl = tmp;
}
}
return dp[x][y] = maxl+;
} int main()
{
while(cin>>n>>m)
{
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf("%d", &h[i][j]);
memset(dp, , sizeof(dp));
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
dfs(i, j);//dp每个点为起点能滑的最大长度
int maxlen = ;
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
if(dp[i][j]>maxlen)
maxlen = dp[i][j];
cout<<maxlen<<endl;
} return ;
}
POJ1088(dp)的更多相关文章
- dp例题02. 滑雪问题 (poj1088)
poj1088滑雪问题 题目链接:http://poj.org/status Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得 ...
- POJ1088滑雪(dp+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86411 Accepted: 32318 Description ...
- poj1088 经典DP
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 88296 Accepted: 33100 Description ...
- [POJ1088] 滑雪(递归dp)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- dp——poj1088(Description)
dp可以按照思想大致分为两种,一种是递推的形式,一种是递归的形式(记忆化搜素). 比如求这个题因为无法知道从哪个点开始,所以只能用递归的形式,因为有一个回溯的过程. 但是很多题目既可以用递推也可以用递 ...
- POJ-1088 滑雪 (记忆化搜索,dp)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86318 Accepted: 32289 Description Mich ...
- POJ1088:滑雪(简单dp)
题目链接: http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一 ...
- ACM学习历程—POJ1088 滑雪(dp && 记忆化搜索)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- 经典DP问题--poj1088滑雪
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
随机推荐
- javascript中0.01*2324=23.240000000000002 ?
js中的乘法运算的小问题 0.01*2324=23.240000000000002 ? , 结果为什么出现这么多小数位呢?
- 【poj解题】3663
排序, 遍历,需要裁减 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX ...
- Unity 之 c# 版的 CharacterMotor
using System; using System.Collections; using UnityEngine; // This class just convert from Character ...
- windows服务器下IIS7 安装URL Rewrite(URL重写)模块
URL Rewrite Module是一个基于规则的URL重写引擎,用于在URL被Web服务器处理之前改变请求的URL.对于动态Web应用程序,它可以为用户和seo/seo.html" ta ...
- [iOS]C语言技术视频-04-程序循环结构(while{})
下载地址: 链接: http://pan.baidu.com/s/1o6imQ4U 密码: imuy
- 十大滤波算法程序大全(Arduino精编无错版)(转)
源:十大滤波算法程序大全(Arduino精编无错版) 转载请注明出处:极客工坊 http://www.geek-workshop.com/thread-7694-1-1.html
- OSD的主要实现方法和类型(转)
源:OSD的主要实现方法和类型 目前有两种主要的OSD实现方法:外部OSD发生器与视频处理器间的叠加合成;视频处理器内部 支持OSD,直接在视频缓存内部叠加OSD信息. 外部OSD发生器与视频处理器间 ...
- Github上的600多个iOS开源类库
Github上的600多个iOS开源类库,入下图所示,里面有很多资源,学习积累的好资源 地址:http://github.ibireme.com/github/list/ios/
- object 类 toString() 和 equals() 的覆写
基本作用: objiect类是所有类的父类. 任何一个类定义的时候如果没有明确定义了父类的话,默认父类是Object类. class A extends Object{} 在整个java里面,类的继承 ...
- Java数据结构整理(一)
ava数据结构内容整理关键字: 数据结构 Collection:List.SetMap:HashMap.HashTable如何在它们之间选择一.Array , ArraysJava所有“存储及随机访问 ...