HYR00000 @ 2024-11-17 21:53:27
DFS
哪错了?
#include<bits/stdc++.h>
using namespace std;
int n,m,g[500][500],ans=0,vis[500][500];
string s;
char c;
int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
void dfs(int x,int y){
if(ans==1){
return;
}
if(x==n&&y==m){
ans=1;
}
for(int i=0;i<4;i++){
int tx=x+dx[i],ty=y+dy[i];
if(vis[tx][ty]==0&&tx>=1&&tx<=n&&ty>=1&&ty<=m&&g[tx][ty]==0){
vis[tx][ty]=1;
dfs(tx,ty);
vis[tx][ty]=0;
}
}
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s;
for(int j=1;j<=m;j++){
c=s[j];
if(c=='#'){
g[i][j]=0;
}
if(c=='.'){
g[i][j]=1;
}
}
}
dfs(1,1);
if(ans==1){
cout<<"No";
}
else{
cout<<"Yes";
}
}
by HYR00000 @ 2024-11-17 21:59:21
???
by fire_hua @ 2024-11-26 17:52:40
@HYR00000 就是说string类型的话下标是从0开始的吧