题目
代码
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
const int N = 310;
using namespace std;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int ans;
int g[N][N];
int r, c;
int f[N][N];
int dfs(int x, int y)
{
if(~f[x][y]) return f[x][y];
f[x][y] = 1;
for(int i = 0; i < 4; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if(nx < 1 || ny < 1 || nx > r || ny > c || g[nx][ny] >= g[x][y]) continue;
f[x][y] = max(f[x][y], dfs(nx,ny)+1);
}
return f[x][y];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> r >> c;
for(int i = 1; i <= r; i++)
{
for(int j = 1; j <= c; j++)
{
cin >> g[i][j];
}
}
memset(f, -1, sizeof f);
for(int i = 1; i <= r; i++)
for(int j = 1; j <= c; j++)
{
ans = max(ans, dfs(i,j));
}
cout << ans;
}