http://poj.org/problem?id=1088

dfs过程中,保存经历过的点的最大滑雪距离,依次遍历每一个点的最大距离即可。

#include<iostream>
#include<cstdio>
using namespace std;
int r,c,a[][],maxlen[][] = {};
int dir[][] = {-,,,-,,,,};
int dfs(int x,int y)
{
int maxx = ,len;
for(int i = ;i < ;i++)
{
int xx = x+dir[i][],yy = y+dir[i][];
if(xx < || xx > r || yy < || yy > c) continue;
if(a[x][y] > a[xx][yy])
{
if(maxlen[xx][yy]) len = maxlen[xx][yy]+;
else len = dfs(xx,yy)+;
maxx = max(maxx,len);
}
}
maxlen[x][y] = maxx;
return maxx;
}
int main()
{
cin >> r >> c;
for(int i = ;i <= r;i++)
{
for(int j = ;j <= c;j++) cin >> a[i][j];
}
int ans = ,len;
for(int i = ;i <= r;i++)
{
for(int j = ;j <= c;j++)
{
if(maxlen[i][j] == )
{
len = dfs(i,j);
ans = max(ans,len);
}
}
}
cout << ans << endl;
return ;
}

POJ_1088_dfs的更多相关文章

随机推荐

  1. Intellij IDEA2019.1.3破解

    下载 JetbrainsCrack.jar(链接:https://pan.baidu.com/s/1Dkw1PruzBlEMjcYszNlSZA 提取码:2bf7),放到bin目录下(其实位置可以随便 ...

  2. Spring Cloud Stream消息驱动之RocketMQ入门(一)

    SpringCloudStream目前支持的中间件有RabbitMQ.Kafka,还有我最近在学习的RocketMQ,以下是我学习的笔记 学习Spring cloud Stream 可以先学习一下了解 ...

  3. Don’t Repeat Yourself,Repeat Yourself

    Don't Repeat Yourself,Repeat Yourself Don't repeat yourself (DRY, or sometimes do not repeat yoursel ...

  4. schedule of 2016-10-24~2016-10-30(Monday~Sunday)——1st semester of 2nd Grade

    2016/10/24 Monday forcus:find a way to try to recognize emotions in database2.0(see ppt Week 7) 1.pr ...

  5. 2017CCPC杭州(ABCDJ)

    所有的题目在这里<--- 待补... Problem A. HDU6264:Super-palindrome 题意: 题目定义了一个超级回文串,这个串满足:它的任一奇数长度的串都是回文串. 现在 ...

  6. Centos7下创建和管理用户

    centos服务管理主要命令是systemctl,centos7的服务不再放在/etc/init.d/下;而放在/usr/lib/systemd/system下,centos7系统中systemctl ...

  7. CTPN-自然文本场景检测代码阅读笔记

    TensorFlow代码 https://github.com/eragonruan/text-detection-ctpn 训练 main/train.py 1. utils/prepare/spl ...

  8. nginx负载均衡动态自动更新(微博开源模块nginx-upsync-module使用)

    这几天项目有个需求:负载要求能根据节点健康状态动态的增减.nginx自带的upstram已经很强大,而且基于Nginx Upstream配置动态更新已经有很多开源方案,大多数都是基于生成配置文件后进行 ...

  9. 第一篇博客-- 走上IT路

    首先介绍一下本人,我是一名在校大学生,在一次学长分享学习经验时了解到,写博客可以帮助复习.所以这就是我要写博客的原因. 我是非常喜欢网络安全技术,因此我选择了我这个专业.在接下来的一段时间我会在这里记 ...

  10. python中方法调用和函数调用的区别

    函数调用: 传几个参数,就会有几个实参方法调用: 默认传递一个参数self,至少要定义一个形参