rt
代码:
#include<iostream>
#include<cstring>
using namespace std;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int maxs[101][101];
int n, m, s[101][101], ans = -114514;
int dfs(int x, int y)
{
if(maxs[x][y] != 0)
{
return maxs[x][y];
}
maxs[x][y] = 1;
for(int i = 0; i < 4; i++)
{
int xx = x + dx[i], yy = y + dy[i];
if(xx < 0 || yy < 0 || xx >= n || yy >= n || s[xx][yy] >= s[x][y])
{
continue;
}
maxs[x][y] = max(maxs[x][y], maxs[xx][yy] + 1);
}
return maxs[x][y];
}
int main()
{
memset(maxs, 0, sizeof(maxs));
cin >> n >> m;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
cin >> s[i][j];
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
dfs(i, j);
ans = max(ans, maxs[i][j]);
}
}
cout << ans;
return 0;
}