60分求调!!!
查看原帖
60分求调!!!
1002517
Adorable_楼主2023/7/16 11:42
#include<bits/stdc++.h>
using namespace std;
int n,m,p,step;
string maps[110] = {""};
void dfs(int x,int y)
{
	if(x<0 or y<0) return;
	if(x>n-1 or y>m-1) return;
	if(p == 1 or step>=150) return;
	if(maps[x][y] == '#') return;
	if(x == n-1 and y == m-1) return;
	{
		p = 1;
		return;
	}
	step++;
	if(x+1<n)  dfs(x+1,y);
	if(x-1>=0) dfs(x-1,y);
	if(y+1<m)  dfs(x,y+1);
	if(y-1>=0) dfs(x,y-1);
}
int main()
{
	cin>>n>>m;
	for(int i = 0;i<=n;++i) getline(cin,maps[i]);
//	for(int i = 0;i<=n;i++) cout<<maps[i]<<endl;
	dfs(0,0);
	if(p == 1) cout<<"Yes";
	else cout<<"No";
	return 0;
}
2023/7/16 11:42
加载中...