首页 技术 正文
技术 2022年11月7日
0 收藏 637 点赞 261 浏览 1245 个字

滑雪

Time Limit: 1000MS

Memory Limit: 65536K

Total Submissions: 83276

Accepted: 31159

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

开始以为是简单的DFS搜索,错了几次,才知道思路不对,搜题解才知是记忆化搜索加动态规划

见题少啊

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>using namespace std;
const int MAX = 110;
int Map[MAX][MAX];
int sum;
int R,C;
int Dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
int Dp[MAX][MAX];
int DFS(int x,int y)
{
if(Dp[x][y])
{
return Dp[x][y];
}
int X,Y;
for(int i=0; i<4; i++)
{
X=x+Dir[i][0];
Y=y+Dir[i][1];
if(X>=0&&X<R&&Y>=0&&Y<C&&Map[x][y]>Map[X][Y])
{
int ans=DFS(X,Y);
if(Dp[x][y]<=ans)
{
Dp[x][y]=ans+1;
}
}
}
return Dp[x][y];
}
int main()
{ while(~scanf("%d %d",&R,&C))
{
for(int i=0; i<R; i++)
{
for(int j=0; j<C; j++)
{
scanf("%d",&Map[i][j]);
Dp[i][j] = 0; }
}
sum=0;
for(int i=0; i<R; i++)
{
for(int j=0; j<C; j++)
{
int ans = DFS(i,j);
if(ans>sum)
{
sum=ans;
}
}
}
printf("%d\n",sum+1);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727