#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 105;
int a[MAXN][MAXN], rem[MAXN][MAXN];
int r, c;
int dirx[] = {-1, 1, 0, 0}, diry[] = {0, 0, -1, 1};
int dfs(int x, int y)
{
if (rem[x][y] != -1)
{
return rem[x][y];
}
rem[x][y] = 1;
for (int i = 0; i < 4; i++) //这里一定是从0开始
{
int nx = x + dirx[i];
int ny = y + diry[i];
if (nx < 1 || ny < 1 || nx > r || ny > c)
{
continue;
}
else if (a[x][y] <= a[nx][ny])
{
continue;
}
rem[x][y] = max(rem[x][y], dfs(nx, ny) + 1);
}
return rem[x][y];
}
int main()
{
int sum = 0;
scanf("%d %d", &r, &c);
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
scanf("%d", &a[i][j]);
}
}
memset(rem, -1, sizeof(rem));
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
rem[i][j] = max(rem[i][j], dfs(i, j));
if (rem[i][j] > sum)
{
sum = rem[i][j];
}
}
}
printf("%d\n", sum);
return 0;
}
一开始WA,后来发现dirx和diry这两个数组都是从0开始存的,所以要从0开始循环,以后要注意。