poj1088-滑雪 【dfs 记忆化搜索】
http://poj.org/problem?id=1088
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 79806 | Accepted: 29701 |
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 解题思路:记忆化搜索。
代码:
#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 记忆化搜索】的更多相关文章
- POJ-1088 滑雪 (记忆化搜索,dp)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 86318 Accepted: 32289 Description Mich ...
- POJ1088滑雪(记忆化搜索)
就是用DP,DP[i][j]是在这个(i,j)位置作为起点的最长长度. 因为可能会超时,DP的话每次就是记录,然后就不用回溯了. 很简单的DFS里面的记忆化搜索. #include <stdio ...
- POJ 1088 滑雪 DFS 记忆化搜索
http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...
- POJ1088滑雪(记忆化搜索+DFS||经典的动态规划)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 84297 Accepted: 31558 Description M ...
- POJ1088 滑雪(记忆化搜索)
题目链接. 分析: 状态转移方程 d[i][j] = max(d[i-1][j], d[i+1][j], d[i][j-1], d[i][j+1]). #include <iostream> ...
- 不要62 hdu 2089 dfs记忆化搜索
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...
- dfs+记忆化搜索,求任意两点之间的最长路径
C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...
- 滑雪---poj1088(动态规划+记忆化搜索)
题目链接:http://poj.org/problem?id=1088 有两种方法 一是按数值大小进行排序,然后按从小到大进行dp即可: #include <iostream> #incl ...
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
随机推荐
- 提取数据之goose使用
1.简介 Python-goose项目是用Python重写的Goose,Goose原来是用Java写的文章提取工具.Python-goose的目标是给定任意资讯文章或者任意文章类的网页,不仅提取出文章 ...
- ASP.NET Web Pages:全局页面
ylbtech-.Net-ASP.NET Web Pages:全局页面 1.返回顶部 1. ASP.NET Web Pages - 全局页面 本章介绍全局页面 AppStart 和 PageStart ...
- 杂项:ORM
ylbtech-杂项:ORM 对象关系映射(英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不 ...
- C# 窗体控件输入框大写
// 将 a-z 改为 A-Z // 'a' 'z' && e.KeyChar <= ) e.KeyChar = ();
- 1046 Shortest Distance (20 分)
1046 Shortest Distance (20 分) The task is really simple: given N exits on a highway which forms a si ...
- [UE4]添加射击的准心
其实就是创建一个UI Widget,在UI Widget中添加一个准心图片(png)格式,准心图片设置为屏幕居中对齐,然后在自定义的GameMode中把这个UI Widget添加到视图中.
- linux中的ftp命令
转载至:https://www.cnblogs.com/mingforyou/p/4103022.html 一.ftp的get命令和mget命令有何不同? get一次只下载一个文件:mget一次可以下 ...
- 通过Vim+少量插件配置一个高效简洁的IDE
最近本人在看<TCP/IP Illustrated Volume2:The Implementation>这本书,自然要下载4.4BSD-Lite的源代码配合书本一起研读.以前学习Vim的 ...
- python并发编程之多进程理论部分
原文连接:http://www.cnblogs.com/linhaifeng/articles/7430066.html#_label4 一 什么是进程 进程:正在进行的一个过程或者说一个任务.而负责 ...
- nginx技术分享 (转)
原文地址:http://blog.csdn.net/nethibernate/article/details/6628267 Nginx的作用: HTTP Server 反向代理,用于将用户的请求转发 ...