zhaoxubing @ 2023-03-23 21:09:13
#include<iostream>
#include<cmath>
using namespace std;
int mp[110][110],u[110][110],n,m;
int xx[4] = { -1,1,0,0 };
int yy[4] = { 0,0,-1,1 };
void dfs(int dx, int dy)
{
for (int h = 0; h < 4; h++)
{
int x = dx + xx[h], y = dy + yy[h];
if(x>0&&x<=n&&y>0&&y<=m)
if (mp[x][y] < mp[dx][dy])
{
if (u[x][y] == 0) {//?
u[x][y] = 1;
dfs(x, y);
u[dx][dy] = max(u[x][y] + 1, u[dx][dy]);//回溯
}
else {
u[dx][dy] = max(u[x][y] + 1, u[dx][dy]);
}
}
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> mp[i][j];
int sum = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (u[i][j] == 0) {
dfs(i, j);
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
sum = max(u[i][j], sum);
cout << sum << endl;
return 0;
}
by Yinsh @ 2023-03-23 21:33:45
@zhaoxubing hack:
1 1
1
答案为
by Yinsh @ 2023-03-23 21:35:42
你的代码并没有处理当所有点都无法向四周扩展时的答案,这时答案为
by zhaoxubing @ 2023-03-23 21:48:24
@Yinsh 谢谢大佬,您的帮助实在是很有用,已关注;
by pray4u @ 2023-11-07 15:22:41
@Yinsh 感谢