社区讨论
40分,WA求助
P1605迷宫参与者 3已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @lrufvhbu
- 此快照首次捕获于
- 2024/01/26 17:26 2 年前
- 此快照最后确认于
- 2024/01/26 20:07 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
int n,m,t,sx,sy,ex,ey,x[1010],y[1010];
int a[1010][1010],b[1010][1010];
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void search(int dep,int x,int y)
{
b[x][y]=1;
if(x==ex&&y==ey)
{
ans++;
return;
}
for(int i=0;i<4;i++)
{
int tx=x+dx[i];
int ty=y+dy[i];
if(tx>=1&&ty>=1&&tx<=n&&ty<=m&&a[tx][ty]==0&&b[tx][ty]==0)
{
search(dep+1,tx,ty);
b[x][y]=0;
}
}
}
int main()
{
cin>>n>>m>>t;
cin>>sx>>sy>>ex>>ey;
for(int i=1;i<=t;i++)
{
cin>>x[i]>>y[i];
a[x[i]][y[i]]=1;
}
search(1,sx,sy);
cout<<ans<<endl;
return 0;
}
回复
共 8 条回复,欢迎继续交流。
正在加载回复...