#include<stdio.h> int climb(int a[100][100],int i,int j) { int b,c,d,e; b = c = d = e = 0; if(a[i][j] < a[i-1][j]) b = climb(a,i-1,j) + 1; if(a[i][j] < a[i+1][j]) c = climb(a,i+1,j) + 1; if(a[i][j] < a[i][j-1]) d = climb(a,i,j-1) + 1; if(a[i][j] < a[i][j+1]) e = climb(a,i,j+1) + 1; return (b>c?b:c)>(d>e?d:e)?(b>c?b:c):(d>e?d:e); } int main() { int n,m,i,j; while(scanf("%d %d",&n,&m) != EOF) { int a[100][100] = {0}; for(i = 1;i <= n;i++) for(j = 1;j <= m;j++) scanf("%d",&a[i][j]); int max = 0; for(i = 1;i <= n;i++) for(j = 1;j <= m;j++) if(climb(a,i,j) > max) max = climb(a,i,j); printf("%d\n",max); } } |
Double click to view unformatted code.