博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codevs 2152 滑雪
阅读量:4661 次
发布时间:2019-06-09

本文共 983 字,大约阅读时间需要 3 分钟。

2152 滑雪

 

 时间限制: 1 s
 空间限制: 32000 KB
 题目等级 : 黄金 Gold
 
 
 
题目描述 
Description

trs喜欢滑雪。他来到了一个滑雪场,这个滑雪场是一个矩形,为了简便,我们用r行c列的矩阵来表示每块地形。为了得到更快的速度,滑行的路线必须向下倾斜。

例如样例中的那个矩形,可以从某个点滑向上下左右四个相邻的点之一。例如24-17-16-1,其实25-24-23…3-2-1更长,事实上这是最长的一条。

输入描述 
Input Description

输入文件

第1行: 两个数字r,c(1<=r,c<=100),表示矩阵的行列。

第2..r+1行:每行c个数,表示这个矩阵。

输出描述 
Output Description

输出文件

仅一行: 输出1个整数,表示可以滑行的最大长度。

样例输入 
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

数据范围及提示 
Data Size & Hint

1s

 
 
#include
#include
using namespace std;int ans=0,r,c,f[200][200]={
0},a[200][200];int dx[5]={
0,0,-1,0,1},dy[5]={
0,1,0,-1,0};//深搜寻找最长的路 int dfs(int x,int y){ int nx,ny; if (f[x][y]) return (f[x][y]); for (int i=1;i<=4;i++)//搜寻上下左右四个方向 { nx=x+dx[i]; ny=y+dy[i]; if ((nx>=1)&&(nx<=r)&&(ny>=1)&&(ny<=c)&&(a[x][y]>a[nx][ny]))//这里也可以用a[x][y]

 

转载于:https://www.cnblogs.com/sjymj/p/5303582.html

你可能感兴趣的文章