http://poj.org/problem?id=1088

滑雪
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 79806   Accepted: 29701

Description

Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子

 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

输入的第一行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行,每行有C个整数,代表高度h,0<=h<=10000。

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

解题思路:记忆化搜索。
代码:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; #define N 102 int n,m,a[N][N],h[N][N];
int xy[][]={{,,,-},{,-,,}}; bool Check(int x,int y);
int Dfs(int x,int y); int main(){
int ans=;
scanf("%d %d",&n,&m);
for(int i=;i<n;i++)
for(int j=;j<m;j++)
scanf("%d",&a[i][j]);
memset(h,-,sizeof(h));
for(int i=;i<n;i++)
for(int j=;j<m;j++)
ans=max(ans,Dfs(i,j));
printf("%d\n",ans);
return ;
}
bool Check(int x,int y){
return x>=&&x<n&&y>=&&y<m;
}
int Dfs(int x,int y){
if(h[x][y]!=-) return h[x][y];
int tx,ty;
h[x][y]=;
for(int i=;i<;i++){
tx=x+xy[][i];
ty=y+xy[][i];
if(Check(tx,ty)&&a[x][y]>a[tx][ty]){
h[x][y]=max(h[x][y],Dfs(tx,ty)+);
}else continue;
}
return h[x][y];
}

poj1088-滑雪 【dfs 记忆化搜索】的更多相关文章

  1. POJ-1088 滑雪 (记忆化搜索,dp)

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86318 Accepted: 32289 Description Mich ...

  2. POJ1088滑雪(记忆化搜索)

    就是用DP,DP[i][j]是在这个(i,j)位置作为起点的最长长度. 因为可能会超时,DP的话每次就是记录,然后就不用回溯了. 很简单的DFS里面的记忆化搜索. #include <stdio ...

  3. POJ 1088 滑雪 DFS 记忆化搜索

    http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...

  4. POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 84297   Accepted: 31558 Description M ...

  5. POJ1088 滑雪(记忆化搜索)

    题目链接. 分析: 状态转移方程 d[i][j] = max(d[i-1][j], d[i+1][j], d[i][j-1], d[i][j+1]). #include <iostream> ...

  6. 不要62 hdu 2089 dfs记忆化搜索

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...

  7. dfs+记忆化搜索,求任意两点之间的最长路径

    C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...

  8. 滑雪---poj1088(动态规划+记忆化搜索)

    题目链接:http://poj.org/problem?id=1088 有两种方法 一是按数值大小进行排序,然后按从小到大进行dp即可: #include <iostream> #incl ...

  9. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

  10. POJ 1088 滑雪(记忆化搜索)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description ...

随机推荐

  1. 6-3-1appium iOS

    环境准备 brew install carthage npm i -g ios-deploy brew install libimobiledevice --HEAD brew install ide ...

  2. 1033 To Fill or Not to Fill (25 分)

    1033 To Fill or Not to Fill (25 分) With highways available, driving a car from Hangzhou to any other ...

  3. 1046 Shortest Distance (20 分)

    1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a si ...

  4. tcp_tw_recycle和tcp_timestamps导致connect失败问题

    把服务里面的net.ipv4.tcp_timestamps这个参数设置为0后已经可以正常telnet通了. 具体设置方法: 在/etc/sysctl.conf  里面加入 net.ipv4.tcp_t ...

  5. [UE4]FString常用API

    转自:http://aigo.iteye.com/blog/2279808 将int或float转换为string: 将FString转换为char*: 将string转换为int或者float: 字 ...

  6. Access-Control-Allow-Origin 跨域问题

    1.同源.同源策略(Same origin policy) 同源指的是协议,端口,域名全部相同. 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺 ...

  7. 网络虚拟化中的 offload 技术:LSO/LRO、GSO/GRO、TSO/UFO、RSS、VXLAN

    offload offload特性,主要是指将本来在操作系统协议栈中进行的一些数据包处理(如IP分片.TCP分片.重组.checksum校验等)放到网卡硬件中去做,降低系统 CPU 消耗,提高处理的性 ...

  8. SDOI 2017 天才黑客

    /* 根据claris的 博客以及 beginend 的博客来写的 首先考虑如何求出最短路 可以从样例看出 路径是从边走到边的, 所以我们将边看作点 有共同端点的两边之间 互相连边, 边权为lcp. ...

  9. Angular4之常用指令

    Angular4指令 NgIf <div *ngIf="false"></div> <!-- never displayed --> <d ...

  10. Web 跨域请求(OCRS) 前端解决方案

    1.同源策略如下: URL 说明 是否允许通信 http://www.a.com/a.jshttp://www.a.com/b.js 同一域名下 允许 http://www.a.com/lab/a.j ...