POJ 1088 滑雪(模板题 DFS+记忆化)
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 <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=;
int m,n;
int Map[maxn][maxn],dp[maxn][maxn]; int DFS(int x, int y)
{
if(dp[x][y]!=-)
return dp[x][y]; int dx[]={,,,-},dy[]={,-,,};
int tmax=;
for(int i=; i<; i++)
{
int nx=dx[i]+x, ny=dy[i]+y;
if(nx>=&&nx<m&&ny>=&&ny<n &&Map[nx][ny] < Map[x][y])
tmax=max(tmax, DFS(nx, ny));
}
dp[x][y]=tmax+; return tmax+;
} int main ()
{
//freopen("in.txt", "r", stdin);
memset(Map, -, sizeof(Map));
memset(dp, -, sizeof(dp)); cin>>m>>n;
for(int i=; i<m; i++)
for(int j=; j<n; j++)
cin>>Map[i][j]; int ans=;
for(int i=; i<m; i++)
for(int j=; j<n; j++)
{
dp[i][j]=DFS(i,j);
ans=max(dp[i][j], ans);
} cout<<ans<<endl;
return ;
}
POJ 1088 滑雪(模板题 DFS+记忆化)的更多相关文章
- POJ 1088 滑雪(简单的记忆化dp)
题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...
- poj 1088 滑雪(区间dp+记忆化搜索)
题目链接:http://poj.org/problem?id=1088 思路分析: 1>状态定义:状态dp[i][j]表示在位置map[i][j]可以滑雪的最长区域长度: 2>状态转移方程 ...
- POJ 1088: 滑雪(经典 DP+记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74996 Accepted: 27818 Description ...
- POJ 1191 棋盘分割 【DFS记忆化搜索经典】
题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submission ...
- [ACM] poj 1088 滑雪 (内存搜索DFS)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 73409 Accepted: 27141 Description ...
- poj 1088 滑雪 DP(dfs的记忆化搜索)
题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
- POJ 1088 滑雪(记忆化搜索+dp)
POJ 1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 107319 Accepted: 40893 De ...
- 不要62 hdu 2089 dfs记忆化搜索
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...
随机推荐
- mysql使用存储过程和event定期删除
-- 创建存储过程DELIMITER //CREATE PROCEDURE del_data()BEGIN DELETE FROM t_route_status WHERE route_date &l ...
- 【Java】NO.120.JDK.1.JDK8.1.001-【Java8实战】
Style:Mac Series:Java Since:2018-09-26 End:2018-09-26 Total Hours:1 Degree Of Diffculty:5 Degree Of ...
- python tuple的函数
1. len(tuple) 计算元组元素个数 >>> tuple1 = ('Google', 'Runoob', 'Taobao') >>> len(tuple1) ...
- 安装WIN7/WIN10上的 CPU版本的TensorFlow
随手记 ancaconda Anaconda2-5.0.1-Windows-x86_64(python3.5 ancaconda python-3.5.2-amd64 安装TensorFlow的时候自 ...
- tplink路由器DMZ设置
设置完成后,DMZ主机访问不了? 请排查以下方面: 1.确认服务器搭建成功,即内网可以正常访问: 2.确认在DMZ主机中填写的服务器IP地址正确: 3.宽带直接连接服务器并配置上网,确认外网可以正常访 ...
- 2015 北京网络赛 E Border Length hihoCoder 1231 树状数组 (2015-11-05 09:30)
#1231 : Border Length 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Garlic-Counting Chicken is a special spe ...
- K-wolf Number (数位DP)
题意:求区间内有多少个数满足条件:任意相邻的k个数位都不相等. 思路:老套路 #include<bits/stdc++.h> using namespace std; typedef lo ...
- SpringMvc HandlerMethodResolver 的 handlerMethods & ServletHandlerMethodResolver 的 mappings 在哪里初始化的 ?
HandlerMethodResolver 的 handlerMethods & ServletHandlerMethodResolver 的 mappings 在哪里初始化的 ? 如下图:
- Linux基础命令---lpq查看打印队列
lpq lpq指令用来显示当前打印队列的状态.如果命令行中没有指定打印机或类,则将显示默认目标上排队的作业. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.ope ...
- PriorityQueue 源码分析
public boolean hasNext() { return cursor < size || (forgetMeNot != null && !forgetMeNot.i ...