BDFZ_lzq @ 2024-07-24 17:40:01
#include<bits/stdc++.h>
using namespace std;
bool b[105][105];
bool end12=0;
int n,m;
void dfs(int x,int y)
{
if(x>0&&x<=n&&y<=m&&y>0&&end12==0&&b[x][y]==1)
{
if(x==n&&m==y)
{
end12=1;
cout<<"Yes";
return;
}
b[x][y]=0;
dfs(x,y+1);
dfs(x,y-1);
dfs(x-1,y);
dfs(x+1,y);
b[x][y]=1;
}
return;
}
int main()
{
cin>>n>>m;
getchar();
for(int z=1;z<=n;z++)
{
for(int y=1;y<=m;y++)
{
if(getchar()=='#')
{
b[z][y]=0;
}
else
{
b[z][y]=1;
}
}
getchar();
}
dfs(1,1);
if(end12==0)
{
cout<<"No";
}
return 0;
}
by FIRESTARS @ 2024-07-24 17:41:13
@BDFZ_lzq 哥们,谁让你回溯了?
by FIRESTARS @ 2024-07-24 17:42:39
@BDFZ_lzq 删掉dfs里的 b[x][y]=1;
就能A。
by BDFZ_lzq @ 2024-07-24 17:48:02
@FIRESTARS 我是智障
by FIRESTARS @ 2024-07-24 17:49:04
@BDFZ_lzq 想当年我做奶酪这题的时候也因为回溯而T了
by FIRESTARS @ 2024-07-24 17:49:29
@BDFZ_lzq P3958