30 pts
  • 板块P1605 迷宫
  • 楼主yyjw14
  • 当前回复4
  • 已保存回复4
  • 发布时间2023/10/8 21:30
  • 上次更新2023/11/2 14:52:29
查看原帖
30 pts
916380
yyjw14楼主2023/10/8 21:30
#include<bits/stdc++.h>
#include<cmath> 
using namespace std;
int i,j,k,xx,xxx,yy,yyy,cnt,m,n,ans,sum,q;
const int N = 6;
int a[N][N];
int xc[]={0,0,1,-1},yc[]={-1,1,0,0};
int tmp[N][N];
void dfs(int x,int y)
{
	
	int tx,ty ;
	if(tx==xxx&&ty==yyy)
	{
		sum++;
		return;
	}
	else
	{
		for(q=0;q<4;q++)
		{
			tx=x+xc[q];
			ty+=y+yc[q];
			if(a[tx][ty]!=1&&1<=tx&&tx<=i&&1<=ty&&ty<=j&&tmp[tx][ty]!=1)
			{
				a[tx][ty]=1;
				dfs(tx,ty);
				a[tx][ty]=0;
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>i>>j>>k;
	cin>>xx>>yy>>xxx>>yyy;
	for(cnt=1;cnt<=k;cnt++)
	{
		cin>>m>>n;
		tmp[m][n]=1;
	}
	a[xx][yy]=1; 
	dfs(xx,yy);
	cout<<sum;
	return 0;
}
  
2023/10/8 21:30
加载中...