View Code of Problem 217

import java.util.*;
public class Main {
public static void main(String[] args) {
	Scanner in=new Scanner(System.in);
	while(in.hasNext()) {
		int n=in.nextInt();
		int m=in.nextInt();
		int [][]louti=new int [n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				louti[i][j]=in.nextInt();
			}
		}
		Main ob=new Main();
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
			ob.pa(louti,i,j,0);
			}
		}
		System.out.println(ob.max+1);
	}
}
public  int max=0;
public  void pa(int[][]a,int n,int m,int step) {
	if(step>max) {
		max=step;
	}
	int [][]next= {{1,0},{0,1},{-1,0},{0,-1}};
	for(int k=0;k<4;k++) {
		int n2=n+next[k][0];
		int m2=m+next[k][1];
		if(n2>=0&&m2>=0&&n2<a.length&&m2<a[0].length&&a[n][m]>a[n2][m2]) {
			pa(a,n2,m2,step+1);
		}
	}
}
 
}

Double click to view unformatted code.


Back to problem 217