T-T
2024-08-16 16:44:26
发布于:广东
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
int n,m,a[N][N],vis[N][N];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int flag=0;
void dfs (int x,int y)
{
vis[x][y]=1;
if(xn and ym)
{
flag=1;
return;
}
for(int i=0;i<4;++i)
{
int nx =dx[i]+x;
int ny =dy[i]+y;
if(nx>=1 and nx<=n and ny>=1 and ny<=m and vis[nx][ny]==0 and a[nx][ny]==0)
{
dfs(nx,ny);
}
}
}
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(flag==1) cout<<"YES";
else cout<<"NO";
return 0;
}
这里空空如也
有帮助,赞一个