求助大佬!
查看原帖
求助大佬!
687911
chenyihao2011楼主2024/3/16 21:16

也不知道该怎么调

#include<bits/stdc++.h>
using namespace std;

int n,m;
char c;
bool cnt=false;
int a[105][105]={0};

int dfs(int x,int y){
	if(x==n and y==m){
		cnt=true;
		return true;
	}
	int d,b;
	int xi[5]={0,1,0,-1,0};
	int yi[5]={0,0,1,0,-1};
	for(int i=1;i<=4;i++){
		d=x+xi[i];
		b=y+yi[i];
		if(d<=n and d>=1 and b<=m and b>=1 and a[x][y]==1) return dfs(d,b);
	}
	return false;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c;
			if(c=='.') a[i][j]=1;
    	}
	}
	cnt=dfs(1,1);
	if(cnt) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
} 
2024/3/16 21:16
加载中...