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 516 17 18 19 615 24 25 20 714 23 22 21 813 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]