以下是代码
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int f[N][N], tu[N][N];
int n, m, xx, yy, r, c, high=INT_MIN;
int fx[4] = {0, 0, 1, -1};
int fy[4] = {1, -1, 0, 0};
int dfs(int x, int y)
{
if (f[x][y] > 0)
return f[x][y];
int xx, yy;
for (int i = 0; i < 4; i++)
{
xx = x + fx[i];
yy = y + fy[i];
if (xx >= 1 && yy >= 1 && xx <= n && yy <= m )
{
if (tu[xx][yy] < tu[x][y])
{
f[x][y] = max(f[x][y], dfs(xx, yy));
}
}
}
return ++f[x][y];
}
int main()
{
cin >> r >> c;
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
cin >> f[i][j];
}
}
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
high=max(dfs(i,j),high);
}
}
cout << high << endl;
return 0;
}