514czh @ 2024-10-12 13:08:15
#include<bits/stdc++.h>
using namespace std;
int x[]={1,-1,0,0};
int y[]={0,0,1,-1};
int f=0;
int n,m;
char a[105][105];
void dfs(int xx,int yy){
if(xx==n&&yy==m){
f=1;
return ;
}
for(int i=0;i<4;i++){
if(xx+x[i]<=n&&xx+x[i]>=1&&yy+y[i]>=1&&yy+y[i]<=m&&a[xx+x[i]][yy+y[i]]=='.'){
a[xx+x[i]][yy+y[i]]='#';
dfs(xx+x[i],yy+y[i]);
if(f){
return ;
}
a[xx+x[i]][yy+y[i]]='.';
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int t=1;t<=m;t++){
cin>>a[i][t];
}
}
dfs(1,1);
if(f)
cout<<"Yes";
else cout<<"No";
return 0;
}
by 514czh @ 2024-10-12 13:18:33
玄关
by 514czh @ 2024-10-12 13:23:34
把回溯删了就A了
于是我关了我