HIT2023112282 @ 2024-02-04 16:29:03
#include<bits/stdc++.h>
using namespace std;
int n,m;
int dx[4]={-1,+1,0,0};
int dy[4]={0,0,-1,+1};
char a[110][110];
int v[110][110];
string ans="No";
void search(int x,int y)
{
if(a[x][y]=='#')return;
if(x<1||y<1||x>n||y>m)return;
if(x==n&&y==m)
{
ans="Yes";
return;
}
for(int i=0;i<=3;i++)
{
int nx,ny;
nx=x+dx[i];
ny=y+dy[i];
if(v[nx][ny]==1)continue;
v[nx][ny]=1;
search(nx,ny);
v[nx][ny]=0;
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
search(1,1);
cout<<ans;
return 0;
}
by kexun_kevin @ 2024-02-04 16:36:56
v[nx][ny] = 0;
这行去掉就行了
by HIT2023112282 @ 2024-02-05 21:17:41
@kexun_kevin 感谢,已关注