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中 ...
随机推荐
- Centos7 修改系统时区timezone
Centos7 修改系统时区timezone 注意:修改Linux系统的时区以后,再安装jvm,jvm默认会使用系统的时区.如果系统时区设置错误,安装jvm后,再修改系统的时区,但jvm的时区仍然用不 ...
- DELPHI中完成端口(IOCP)的简单分析(4)
DELPHI中完成端口(IOCP)的简单分析(4) 在我以前写的文章中,一直说的是如何接收数据.但是对于如何发送数据却一点也没有提到.因为从代码量上来说接收的代码要比发送多很多.今天我就来写一下如 ...
- POJ3461 Oulipo 字符串
正解:kmp/哈希 解题报告: 传送门! 这题其实就kmp板子,,,用来复习下kmp的太久没打了QAQ 所以kmp做法就不港了放个代码就是了QAQ #include<algorithm> ...
- 【Python全栈-后端开发】Django进阶2-Form表单
Django进阶2-Form表单 Django的Form主要具有一下几大功能: 生成HTML标签(可以保留上次输入内容) 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页 ...
- Linux Input子系统
先贴代码: //input.c int input_register_handler(struct input_handler *handler) { //此处省略很多代码 list_for_each ...
- Lint found fatal errors while assembling a release target
1.Android 打包错误信息 Generate signed Bundle or APK 打包时,报了一个错,错误信息如下: Error:Execution failed for task ´: ...
- Apache 2.4.27外网访问403(Forbidden)错误
httpd.conf <Directory /> AllowOverride none #Require all denied 注释这句 Allow from all Require al ...
- Window丢失api-ms-win-crt-runtime-l1-1-0.dll
一.现象api-ms-win-crt-runtime-l1-1-0.dll 丢失 二.第一种方案,缺什么补什么http://download.csdn.net/download/su749520/10 ...
- 【LeetCode每天一题】Spiral Matrix II(螺旋数组II)
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral ord ...
- solr简单搜索案例
solr简单搜索案例 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字搜索商品信息,根据商品分类.价格过滤搜索结果,也可以根据价格进行排序,实现分页. 架构分为: 1. solr服务器 2. ...