1 #include<cstdio>
2 #include<iostream>
3 using namespace std;
4
5 const int maxn = 1005;
6
7 int g[maxn][maxn], ans[maxn][maxn];
8 int f[4] = {1, 0, -1, 0};
9 int f1[4] = {0, -1, 0, 1};
10 int r, c, p;
11
12 inline int dfs(int x, int y){
13 if(ans[x][y]) return ans[x][y];
14 int t = 1;
15 for(int i = 0; i <= 3; i++){
16 int nx = x + f[i];
17 int ny = y + f1[i];
18 if(nx >= 1 && ny >= 1 && nx <= r && ny <= c && g[x][y] > g[nx][ny])//是否越界
19 t = max(dfs(nx, ny) + 1, t);//包括自身
20 }
21 ans[x][y] = t;//保存
22 return ans[x][y];//返回
23 }
24
25 int main(){
26 scanf("%d%d", &r, &c);
27 for(int i = 1; i <= r; i++){
28 for(int j = 1; j <= c; j++){
29 scanf("%d", &g[i][j]);
30 }
31 }
32 for(int i = 1; i <= r; i++){
33 for(int j = 1; j <= c; j++){
34 ans[i][j] = dfs(i, j);
35 p = max(p, ans[i][j]);//取最大
36 }
37 }
38 printf("%d
", p);
39 return 0;
40 }