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 ...
随机推荐
- js/jq仿window文件夹框选操作插件
0.先给大家看看效果: 1.创建一个index.html文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
- 邁向IT專家成功之路的三十則鐵律 鐵律十二:IT人養生之道-德行
所謂的「養生」在中國古代裡所指的是針對內在精神層面修為的提升,到了近代中醫所謂的養生,則除了包含最根本的內在精神層面之外,還涵蓋了外在身體的養護.在現今各行各業的人士當中,嚴格來說都應該要有一套專屬的 ...
- WCF中常用的binding方式 z
WCF中常用的binding方式: BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务.用于兼容旧的Web ASMX 服务. WSHttpBinding: 比 Bas ...
- Android开发者选项——Gpu呈现模式分析
对于Android用户来说,无论你用的什么品牌的手机,在开发者选项中都能发现“玄学曲线”的开关,之所以称其为玄学曲线,还是因为它被很多网友用于测试一个说不清道不明的东西——流畅度.到底多流畅才叫流畅, ...
- 阿里云云服务器ubuntu配置nginx+uwsgi+django记录文档
1 安装ssh 1 sudo apt-get update 2 sudo apt-get install openssh-server 3 sudo ps -e |grep ssh 有sshd ...
- css3 - 动态伪类
动态伪类分为以下几种: 1. hover(经过) 2. active(点击后) 3. focus(聚焦) - input专用 4. visited(访问后) 使用:
- hql 时间
1.hql中时间格式转换 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d ...
- vue2 + typescript2 自定义过滤器
1.定义一个过滤器 // color-directive.ts import { DirectiveOptions } from 'vue' const directive: DirectiveOpt ...
- Jenkins和Maven构建持续集成
真是运维的福利,不用在敲Linux命令了 须要的工具:Linux或window.Jenkins.tomcat7.Jdk.maven.项目部署的war包 1.首先从Jenkins官网下载最新的Jenki ...
- Cts框架解析(15)-任务运行完
case运行完成后.会回到CtsTest的run方法中: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXRmb290YmFsbA==/font/5a6L ...