POJ 1088 滑雪 ( DFS+动态规划思想 )
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 79519 | Accepted: 29581 |
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#define INF 0x3f3f3f3f
#define N 100+2
#define R_for(i, n) for(i=0; i<n; i++)
#define r_for(i, n) for(i=1; i<=n; i++)
#define D_for(i, n) for(i=n-1; i>=0; i--)
#define d_for(i, n) for(i=n; i>=1; i--) using namespace std;
int n, m;
int map[N][N];
int dis[N][N];
int f[4][2]= {{0, -1}, {0, 1}, {-1, 0}, {1, 0} };
struct node
{
int x, y;
} t;
int ans; int DFS(int posi, int posj)
{
int i;
if(dis[posi][posj]!=0)
return dis[posi][posj]; for(i=0; i<4; i++)
{
int xx=posi+f[i][0];
int yy=posj+f[i][1]; if((xx>=0&&xx<n)&&(yy>=0&&yy<m) && map[xx][yy]<map[posi][posj])
{
int dd=DFS(xx, yy);
if(dis[posi][posj]<=dd)
dis[posi][posj]=dd+1;
}
}
return dis[posi][posj];
} int main()
{
int i, j; while(scanf("%d %d", &n, &m)!=EOF)
{
R_for(i, n)
R_for(j, m)
{
scanf("%d", &map[i][j] );
} memset(dis, 0, sizeof(dis)); ans=-1;
R_for(i, n)
{
R_for(j, m)
{
int dd=DFS(i ,j);
if(dd>ans)
{
ans=dd;
}
}
}
printf("%d\n", ans+1);
}
return 0;
}
POJ 1088 滑雪 ( DFS+动态规划思想 )的更多相关文章
- POJ 1088 滑雪 DFS 记忆化搜索
http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...
- POJ 1088 滑雪(记忆化搜索+dp)
POJ 1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 107319 Accepted: 40893 De ...
- POJ 1088 滑雪(记忆化搜索)
滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 92384 Accepted: 34948 Description ...
- POJ 1088 滑雪 【记忆化搜索经典】
题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: ...
- POJ 1088 滑雪 -- 动态规划
题目地址:http://poj.org/problem?id=1088 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...
- [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 滑雪(模板题 DFS+记忆化)
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- OpenJudge/Poj 1088 滑雪
1.链接地址: bailian.openjudge.cn/practice/1088 http://poj.org/problem?id=1088 2.题目: 总Time Limit: 1000ms ...
随机推荐
- python安装numpy和matplotlib
1.从该链接下载对应的whl文件 2.按照下面的方式从whl文件安装即可 windows7 python2.7 1.用管理员方式打开cmd 2.首先通过pip命令安装wheel 如果提示’pip’不是 ...
- jenkins发布普通项目、配置自动上线自动部署
1.以root用户运行jenkins是不专业的 刚开始用jenkins时用jenkins这个普通用户运行程序,始终无法连接到gitlab,报错如下: 先是把修改jenkins上的git路径,将git修 ...
- nfs详解及实现全网备份
1.统一hosts cat /etc/hosts 172.16.1.5 lb01 172.16.1.6 lb02 172.16.1.7 web02 172.16.1.8 web01 172.16.1. ...
- spring版本不兼容JDK问题
在实验书上Spring项目的时候出现一个问题,导入包和使用注释的时候eclipse出现报错. 导入包报错:The import org cannot be resolved 注释报错:componen ...
- python学习笔记之heapq内置模块
heapq内置模块位于./Anaconda3/Lib/heapq.py,提供基于堆的优先排序算法 堆的逻辑结构就是完全二叉树,并且二叉树中父节点的值小于等于该节点的所有子节点的值.这种实现可以使用 h ...
- DELPHI10.2的LINUX数据库开发环境配置
DELPHI10.2的LINUX数据库开发环境配置 ubuntu使用firedac访问mysql1.安装mysql-client包sudo apt-get install mysql-client m ...
- iOS真机测试,为Provisioning添加设备
------------添加设备到provisioning------------- 1,登陆https://developer.apple.com/devcenter/ios/index.actio ...
- Android 源码编译记录
问题1:Can't locate Switch.pm in @INC (you may need to install the Switch module) (@INC contains: /etc/ ...
- Java中的BigInteger在ACM中的应用
Java中的BigInteger在ACM中的应用 在ACM中的做题时,常常会遇见一些大数的问题.这是当我们用C或是C++时就会认为比較麻烦.就想有没有现有的现有的能够直接调用的BigInter,那样就 ...
- es6 对象浅拷贝的2种方法
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...