滑雪
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 79519   Accepted: 29581

Description

Michael 喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个 区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子

 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

输入的第一行表示区域的行数R和列数C(1 <= R,C <= 100)。下面是R行,每行有C个整数,代表高度h,0<=h<=10000。

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+动态规划思想 )的更多相关文章

  1. POJ 1088 滑雪 DFS 记忆化搜索

    http://poj.org/problem?id=1088 校运会放假继续来水一发^ ^ 不过又要各种复习,功课拉下了许多 QAQ. 还有呀,就是昨天被一个学姐教育了一番,太感谢了,嘻嘻^ ^ 好了 ...

  2. POJ 1088 滑雪(记忆化搜索+dp)

    POJ 1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 107319   Accepted: 40893 De ...

  3. POJ 1088 滑雪(记忆化搜索)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 92384   Accepted: 34948 Description ...

  4. POJ 1088 滑雪 【记忆化搜索经典】

    题目链接:http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:  ...

  5. POJ 1088 滑雪 -- 动态规划

    题目地址:http://poj.org/problem?id=1088 Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当 ...

  6. [ACM] poj 1088 滑雪 (内存搜索DFS)

    滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 73409   Accepted: 27141 Description ...

  7. poj 1088 滑雪 DP(dfs的记忆化搜索)

    题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 ...

  8. POJ 1088 滑雪(模板题 DFS+记忆化)

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  9. OpenJudge/Poj 1088 滑雪

    1.链接地址: bailian.openjudge.cn/practice/1088 http://poj.org/problem?id=1088 2.题目: 总Time Limit: 1000ms ...

随机推荐

  1. 51nod 1092 回文字符串【LCS】

    1092 回文字符串 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串.每个字符 ...

  2. Maven配置tomcat和jetty插件来运行项目

    针对eclipse中的Run on Server有些情况下并不是那么好操作,比如配置maven下的springmvc插件,如果使用此方法运行会很容易出现组件缺少导致错误出现一大堆的问题. 那么针对这种 ...

  3. nginx 自签名https

    繁杂的命令,以下准备写好的sh,拷贝https.sh文件,设置执行权限:chmod u+x https.sh #!/bin/sh # create self-signed server certifi ...

  4. filter 中用spring StopWatch 监控请求执行时间

    在filter中用spring stopWatch 来统计每个请求的执行时间: 虽然在firefox 中可以清楚的看到每个请求的执行时间,但是为了测试,记录日志, 方便以后查询维护. 还是必要的,下面 ...

  5. JavaEETest

    原文:https://github.com/lenve/JavaEETest

  6. JAVA微信开发:[17]如何获取所有关注用户

    该方法获取所有关注公共账号的微信用户的openId集合, 再通过openId集合既可以获取所有的用户的信息.   /** * 获取所有的关注用户 * * @return */ public  List ...

  7. xgboost的SparkWithDataFrame版本实现

    再xgboost的源码中有xgboost的SparkWithDataFrame的实现,如下:https://github.com/dmlc/xgboost/tree/master/jvm-packag ...

  8. 第一个Hello,OS World操作系统

    来自:清泛网 - http://www.tsingfun.com/html/2015/dev_0804/hello_os_word_my_first_os.html 首先阐述下程序运行的基本原理:计算 ...

  9. idea2018注册方法

    下面是具体的破解激活步骤: 1. 下载破解补丁文件,路径为:http://idea.lanyus.com/jar/JetbrainsCrack-2.7-release-str.jar 2.将补丁放在安 ...

  10. windows 平台 ffmeg h264 硬编码

    本文讲述windows 平台下ffmpeg如何利用intel media SDK 进行 h264硬编码(测试版本为3.2.2). ffmeg硬编编码的流程与软件编码流程相同,唯一不同的地方在初始化en ...