View Code of Problem 17

#include<stdio.h>
int climb(int a[100][100],int i,int j);
int main(){
	int n,m,step;
	while(scanf("%d %d",&n,&m)!=EOF){    
		int a[100][100]={0};
		int max = 0; 
		for(int i=1;i<=n;i++)              
			for(int j=1;j<=m;j++)
				scanf("%d",&a[i][j]);

		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				step=climb(a,i,j);
				if(step>max){
					max=step;
				}
			}
		}
		printf("%d\n",max);
	}
}
 
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);
}

Double click to view unformatted code.


Back to problem 17