- 清帝之惑之顺治
- 2018-07-21 19:09:27 @
import java.util.Scanner;
public class Main {
public int[][] m = new int[501][501];
public int[][] dp = new int[501][501];
public int[] mx = { 0, 1, 0, 0, -1 };
public int[] my = { 0, 0, 1, -1, 0 };
public int r, c;
public Main() {
int i = 0, j = 0;
Scanner sc = new Scanner(System.in);
r = sc.nextInt();
c = sc.nextInt();
for (i = 1; i <= r; i++)
for (j = 1; j <= c; j++) {
m[i][j] = sc.nextInt();
dp[i][j] = 1;
}
}
public int dpSearch(int x, int y) {
if (dp[x][y] > 1)
return dp[x][y];
int i = 0, j = 0;
boolean flag = false;
for (i = 1; i <= 4; i++) {
int k = x + mx[i];
int v = y + my[i];
if (k >= 1 && k <= r && v >= 1 && v <= c && m[k][v] < m[x][y]) {
dp[x][y] = Math.max(dp[x][y], dpSearch(k, v) + 1);
}
}
return dp[x][y];
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Main dpClass = new Main();
int max = -1;
for (int i = 1; i <= dpClass.r; i++)
for (int j = 1; j <= dpClass.c; j++)
max = Math.max(max, dpClass.dpSearch(i, j));
System.out.println(max);
}
}