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
25
从任意一点出发,可以滑行的最长距离.(从高往低走)
思路:列举每一个点 a(i,j) 初始时设置len[i][j] = 0
从这个点上下左右四个方向走一下,找到最大的那个+1,就是我的最大距离了.如果这个点周围都比我大,我就是1,将这个点初始化好,若遇到这个点的len[i][j] != 0 直接返回值就好
// poj 滑雪.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 110;
int h[maxn][maxn];
int len[maxn][maxn];
int r,c;
int s[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
void dp(int x,int y){
if(len[x][y] != 0){
return ;
}
int maxlen = 0;
for(int i = 0;i<4;i++){
int tx = x+ s[i][0];
int ty = y+ s[i][1];
if(tx<0 || tx>=r || ty < 0 || ty >= c)
continue;
if(h[tx][ty] < h[x][y] ){
maxlen = max(maxlen,len[tx][ty]);
}else
continue;
}
len[x][y] = maxlen+1;
}
int _tmain(int argc, _TCHAR* argv[])
{
scanf("%d%d",&r,&c);
fill(h[0],h[0]+r*c,0);
fill(len[0],len[0]+r*c,0);
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
scanf("%d",&h[i][j]);
}
}
int maxl = 0;
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
maxl = max (maxl,len[i][j]);
}
}
printf("%d\n",maxl);
system("pause");
return 0;
}