You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
817 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int INF = 0x3f3f3f3f;
int n, m;
int a[N][N];
int dx[] = {-1, 0, 1, 0}; //上右下左
int dy[] = {0, 1, 0, -1}; //上右下左
int res;
/*
3 3
3 2 1
3 4 5
2 1 3
答案:
4
*/
void dfs(int x, int y, int last, int cnt) {
res = max(res, cnt);
for (int i = 0; i < 4; i++) {
int tx = dx[i] + x, ty = dy[i] + y;
if (tx <= 0 || tx > n || ty <= 0 || ty > m) continue;
if (a[tx][ty] < last)
dfs(tx, ty, a[x][y], cnt + 1);
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
dfs(i, j, INF, 0);
printf("%d\n", res - 1);
return 0;
}