View Code of Problem 17

#include <cstdio>
#include <iostream>
using namespace std;
int mmap[100][100]={0};
int max(int t,int l,int r,int b){
	int max=t;
	if(max<l)
		max=l;
	if(max<r)
		max=r;
	if(max<b)
		max=b;
	return max; 
}
int digui(int i,int j,int curent){
	int t=0,l=0,r=0,b=0;
	int top,left,right,bottom;
	top=mmap[i-1][j];
	left=mmap[i][j-1];
	right=mmap[i][j+1];
	bottom=mmap[i+1][j]; 
	
	if(top>curent){
		t=digui(i-1,j,top)+1;
	}
	if(left>curent){
	
		l= digui(i,j-1,left)+1;
	}
	if(right>curent){
	
		r= digui(i,j+1,right)+1;
	}
	if(bottom>curent){
	
		b=digui(i+1,j,bottom)+1;
	}
	return max(t,l,r,b);
	
}
int main(){
	int n,m;
	while(cin>>n>>m){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>mmap[i][j];
			}
		}
		int maxs=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				int res=digui(i,j,mmap[i][j]);
				if(maxs<res)
					maxs=res;
			}
			
		}
		cout<<maxs<<endl;	
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 17