错了,大佬求助
查看原帖
错了,大佬求助
843763
LichKing_Arthas楼主2023/10/17 20:40

测试点信息

#include<bits/stdc++.h>
using namespace std;
string ma[100];
int n,m,f;
int l[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
bool dfs(int x,int y){
	if(x==n && y==m) { cout<<"No";f=1; }
	for(int i=0;i<4;i++){
		int xx=x+l[i][0];
		int yy=y+l[i][1];
		if(ma[xx][yy]=='.' && xx>0 && xx<=n && yy>0 && yy<=m){
			ma[xx][yy]='#';
			dfs(xx,yy);
			ma[xx][yy]='.';
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)  cin>>ma[i];
	ma[1][1]='#';
	dfs(1,1);
	if(f!=1)  cout<<"Yes";
	return 0;
}
2023/10/17 20:40
加载中...