70pts球
  • 板块P1605 迷宫
  • 楼主xunuowei819
  • 当前回复11
  • 已保存回复11
  • 发布时间2024/9/20 19:30
  • 上次更新2024/9/20 20:16:41
查看原帖
70pts球
1401381
xunuowei819楼主2024/9/20 19:30

rt

#include<bits/stdc++.h>
using namespace std;
int n,m,t,sx,sy,ex,ey,ans;
bool a[1145][1145];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void bfs(int x,int y)
{
	for(int i=0;i<4;i++)
	{
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(x==ex&&y==ey)
		{
			ans++;
			return;
		}
		if(nx<=n&&nx>0&&ny<=m&&ny>0&&a[nx][ny]==0)
		{
			a[nx][ny]=1;
			bfs(nx,ny);
			a[nx][ny]=0; 
		}
	}
}
int main()
{
	cin>>n>>m>>t>>sx>>sy>>ex>>ey;
	for(int i=1;i<=t;i++)
	{
		int nx,ny;
		cin>>nx>>ny;
		a[nx][ny]=1;
	}
	bfs(sx,sy);
	cout<<ans;
	return 0;
}
2024/9/20 19:30
加载中...