chen_1111 @ 2024-10-03 18:39:10
#include<bits/stdc++.h>
using namespace std;
int n,m,vis[105][105];
char a[105][105];
bool flag=true;
void dfs(int x,int y)
{
vis[x][y]=1;
if(x==n&&y==m)
{
cout<<"Yes";
flag=false;
return;
}
if(a[x+1][y]=='.'&&vis[x+1][y]==0)
dfs(x+1,y);
else if(a[x][y+1]=='.'&&vis[x][y+1]==0)
dfs(x,y+1);
else if(a[x][y-1]=='.'&&vis[x][y-1]==0)
dfs(x,y-1);
else if(a[x-1][y]=='.'&&vis[x-1][y]==0)
dfs(x-1,y);
if(x==1&&y==1&&flag)
cout<<"No";
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
dfs(1,1);
}
by fire_hua @ 2024-11-26 17:56:05
不要用else if每一种可能都得试一试的