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 ...
随机推荐
- IP分段小记
192.168.0.1 个人电脑:0.2-0.50 硬件开发板:0.51-0.100 机器人工控机:0.101-0.200 激光雷达:192.168.254.51~100 编码器板子:192.168. ...
- 教你写Linux设备驱动程序:一个简短的教程
教你写Linux设备驱动程序:一个简短的教程 http://blog.chinaunix.net/uid-20799298-id-99675.html
- BZOJ1014火星人prefix Splay維護序列 + 字符串哈希
@[Splay, 哈希] Description 火星人最近研究了一种操作:求一个字串两个后缀的公共前缀.比方说,有这样一个字符串:\(madamimadam\), 我们将这个字符串的各个字符予以标号 ...
- MVP的理解和使用
MVP大家应该差不多都知道了,他其实是MVC的升华版,差不多是在view和model中加了一个调节器,这样view不能直接调用model中得数据,而是通过presenter来进行操作,此外Presen ...
- jquery怎么找到元素下面的第一个子元素
<ul><li>11</li><li>22</li><li>33</li><li>44</li&g ...
- npm、yarn、pnpm
它们都是当前主流的包管理工具 pnpm:https://github.com/pnpm/pnpm yarn: https://github.com/yarnpkg/yarn npm: https:// ...
- xpath的匹配规则
starts-with 匹配一个属性开始位置的关键字 contains 匹配一个属性值中包含的字符串 text() 匹配的是显示文本信息,此处也可以用来做定位用 i.e. //input[starts ...
- 每天进步一点点—SQL优化
一. SQL优化 1. 通过show status 命令了解各种SQL的运行频率 mysql>show status like 'Com_%'; +----------- ...
- boost exception jam0.exe 异常错误
在Windows 8 64 bit下执行boost_1_53_0的bootstrap.bat出现了jam0.exe执行错误 搜索网页发现需要修改两处文件: tools/build/v2/engine/ ...
- 转:android studio入门合集
http://blog.csdn.net/column/details/zsl-androidstudio.html