何处大神,求解
2025-03-01 07:38:13
发布于:浙江
6阅读
0回复
0点赞
何处大神,求解:
#include<iostream>
using namespace std;
int n,m,a[45][45],fx[4][2]={1,0,-1,0,0,-1,0,1};
void dfs(int x,int y){
if(a[x][y]==1){
cout<<"NO";
}
a[x][y]=2;
for(int i=0;i<=4;i++){
int newx=x+fx[i][0],newy=y+fx[i][1];
if(a[newx][newy]==0&&newx>0&&newy>0&&newx<=n&&newy<=m){
dfs(newx,newy);
}
}
}
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);
if(a[n][m]==2){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个