KuaiYun @ 2022-12-21 00:38:05
using namespace std;
int a[100][100],vis[100][100];
int m,n,ans;
void init(){
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) vis[i][j]=0;
}
void search(int x,int y,int step){
if(step>ans) ans=step;
if(x-1>=1&&!vis[x-1][y]&&a[x-1][y]<a[x][y])
{
vis[x-1][y]=1;
search(x-1,y,step+1);
vis[x-1][y]=0;
}
if(y-1>=1&&!vis[x][y-1]&&a[x][y-1]<a[x][y])
{
vis[x][y-1]=1;
search(x,y-1,step+1);
vis[x][y-1]=0;
}
if(x+1<=n&&!vis[x+1][y]&&a[x+1][y]<a[x][y])
{
vis[x+1][y]=1;
search(x+1,y,step+1);
vis[x+1][y]=0;
}
if(y+1<=m&&!vis[x][y+1]&&a[x][y+1]<a[x][y])
{
vis[x][y+1]=1;
search(x,y+1,step+1);
vis[x][y+1]=0;
}
return ;
}
int main(){
cin>>m>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) cin>>a[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
init();
search(i,j,1);
}
cout<<ans;
}
by KuaiYun @ 2022-12-21 13:59:39
能过八个点,如果把init函数去掉能多过一个,,,很费解