#include<stdlib.h> #include<stdio.h> int n,m; int stair[1000][1000]={0}; int search(int i,int j){ int l=0,u=0,r=0,d=0; if(stair[i][j]>stair[i+1][j] && stair[i][j]>stair[i-1][j] && stair[i][j]>stair[i][j+1] && stair[i][j]>stair[i][j-1]) return 0; else{ if(stair[i][j]<stair[i][j-1]){ l = 1 + search(i,j-1); } if(stair[i][j]<stair[i-1][j]){ u = 1 + search(i-1,j); } if(stair[i][j]<stair[i][j+1]){ r = 1 + search(i,j+1); } if(stair[i][j]<stair[i+1][j]){ d = 1 + search(i+1,j); } } int max1 = l >r?l:r; int max2 = u>d?u:d; int max = max1>max2?max1:max2; return max; } int main(){ while((scanf("%d %d",&n,&m)!=EOF)){ for(int i=0; i<=1000; i++) for(int z=0; z<=1000; z++) stair[i][z]=0; for(int i=1; i<=n; i++){ for(int z=1; z<=m; z++) scanf("%d",&stair[i][z]); } int max=0; for(int i=1; i<=n; i++){ for(int z=1; z<=m; z++){ int result = search(i,z); if(result > max) max = result; } } printf("%d\n",max); } return 0; } |
Double click to view unformatted code.