蒟蒻,大佬勿喷%%
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e2+5;
int dx[5] = {0,0,1,-1},
dy[5] = {1,-1,0,0};
int n,m;
bool vis[N][N],b[N][N],c;
void dfs(int x,int y)
{
if(x<1 or y<1 or x>n or y>m or b[x][y] or c or vis[x][y]) return;
if(x == n and y == m)
{
c = 1;
return;
}
vis[x][y] = 1;
for(int i = 0;i<4;i++)
{
dfs(x+dx[i],y+dy[i]);
}
//vis[x][y] = 0;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin>>n>>m;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
{
char c;
cin>>c;
if(c == '#') b[i][j] = 1;
}
dfs(1,1);
if(c) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
这道题为什么不用回溯qwq,回溯就t了,不回溯就过了