dongrunxuan @ 2023-10-28 17:21:21
第52行的-1,不加过5个点,加了过另外5个点 代码如下
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int r,c,ans=1;
int a[maxn][maxn],f[maxn][maxn];
int dfs(int i,int j)
{
if(f[i][j]!=0)
{
return f[i][j];
}
else
{
f[i][j]=1;
if(a[i+1][j]<a[i][j])
{
f[i][j]=max(f[i][j],1+dfs(i+1,j));
}
if(a[i-1][j]<a[i][j])
{
f[i][j]=max(f[i][j],1+dfs(i-1,j));
}
if(a[i][j-1]<a[i][j])
{
f[i][j]=max(f[i][j],1+dfs(i,j-1));
}
if(a[i][j+1]<a[i][j])
{
f[i][j]=max(f[i][j],1+dfs(i,j+1));
}
}
return f[i][j];
}
int main()
{
cin>>r>>c;
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
cin>>a[i][j];
}
}
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
dfs(i,j);
ans=max(ans,f[i][j]);
}
}
cout<<ans-1;
return 0;
}```
by zjpwdyf @ 2023-10-28 18:16:57
dfs中的i,j可能会越界
by dongrunxuan @ 2023-10-28 19:24:02
@zjpwdyf 好的,谢谢