UnSis @ 2024-10-23 20:27:01
#include<iostream>
#include<cstring>
using namespace std;
int h[105][105], dp[105][105];
int r, c;
int dfs(int xj, int yi);
int main()
{
memset(dp, -1, sizeof(dp));
int ans = 0;
cin >> r >> c;
for (int i = 0; i < c; i++)
{
for (int j = 0; j < r; j++)
{
cin >> h[j][i];
}
}
for (int i = 0; i < c; i++)
{
for (int j = 0; j < r; j++)
{
dp[j][i] = dfs(j, i);
if (ans < dp[j][i])
ans = dp[j][i];
}
}
cout << ans;
return 0;
}
int dfs(int xj, int yi)
{
if (dp[xj][yi] != -1)
return dp[xj][yi];
dp[xj][yi] = 1;
if (xj > 0 && h[xj - 1][yi] < h[xj][yi])
dp[xj][yi] = max(dp[xj][yi], dfs(xj - 1, yi) + 1);
if (yi > 0 && h[xj][yi - 1] < h[xj][yi])
dp[xj][yi] = max(dp[xj][yi], dfs(xj, yi - 1) + 1);
if (xj < c - 1 && h[xj + 1][yi] < h[xj][yi])
dp[xj][yi] = max(dp[xj][yi], dfs(xj + 1, yi) + 1);
if (yi < r - 1 && h[xj][yi + 1] < h[xj][yi])
dp[xj][yi] = max(dp[xj][yi], dfs(xj, yi + 1) + 1);
return dp[xj][yi];
}
by 白鲟 @ 2024-10-24 10:08:18
@UnSis
by UnSis @ 2024-10-24 15:51:07
@白鲟 谢谢白鲟佬orz 我喜欢你?