1 #include<iostream>
2 using namespace std;
3 int a[105][105] = {0}, ans[105][105] = {0}, r = 0, c = 0, max1 = 0;
4 void dfs(int x, int y)
5 {
6 int dx[5] = {0, 0, 1, -1}, dy[5] = {1, -1, 0, 0}, i = 0;
7 if(ans[x][y]) return;
8 for(ans[x][y] = 1, i = 0; i < 4; i++)
9 if(x + dx[i] >= 0 && x + dx[i] < r && y + dy[i] >= 0 && y + dy[i] < c && a[x][y] > a[x + dx[i]][y + dy[i]])
10 {
11 dfs(x + dx[i], y + dy[i]);
12 if(ans[x + dx[i]][y + dy[i]] + 1 > ans[x][y])
13 ans[x][y] = ans[x + dx[i]][y + dy[i]] + 1;
14 }
15 if(max1 < ans[x][y]) max1 = ans[x][y];
16 }
17
18 int main(int argc,const char *argv[])
19 {
20 int i = 0, j = 0;
21 cin >> r >> c;
22 for( i = 0; i < r; i++)
23 for( j = 0; j < c; j++)
24 cin >> a[i][j];
25 for(max1 = 0, i = 0; i < r; i++)
26 for(j = 0; j < c; j++)
27 dfs(i, j);
28 cout << max1 << endl;
29 return 0;
30 }