Information
- ID
- 767
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 8
- Tags
- # Submissions
- 1075
- Accepted
- 191
- Uploaded By
#include <iostream>
using namespace std;
const int N=101;
int a[N][N],ma[N][N];
int n,sx,sy,fx,fy,nex,ney,ans;
int opx[5]={1,-1,0,0};
int opy[5]={0,0,1,-1};
void dfs(int x,int y)
{
if(x==fx&&y==fy) ans++;
else{
for(int i=0;i<4;i++)
{
nex=x+opx[i];
ney=y+opy[i];
if(nex>=1&&nex<=n&&ney>=1&&ney<=n&&ma[nex][ney]==0)
{
ma[nex][ney]=1;
dfs(nex,ney);
ma[nex][ney]=0;
}
}
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
if(a[i][j]==1)
ma[i][j]=1;
}
}
cin>>sx>>sy>>fx>>fy;
if(ma[sx][sy]==1||ma[fx][fy]==1)
{
cout<<"NO"<<endl;
}
else
{
dfs(sx,sy);
if(ans==0)
{
cout<<"NO"<<endl;
}
else{
cout<<"YES"<<endl;
}
}
return 0;
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.