大佬们这怎么改啊
  • 板块P1605 迷宫
  • 楼主yyxxggb
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/5 12:48
  • 上次更新2024/3/5 17:34:28
查看原帖
大佬们这怎么改啊
1298543
yyxxggb楼主2024/3/5 12:48
#include <iostream>
using namespace  std;
int a[20][20];//1空2障
int v[20][20];//0为未访问
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int cnt=0;
void dfs(int sx,int sy,int fx,int fy)
{	if(sx==fx&&sy==fy)
	{
		cnt++;
		return;
	}
	v[sx][sy]=1;
	for(int k=0;k<=3;k++)
	{
		int tx,ty;
		tx=sx+dx[k];
		ty=sy+dy[k];
		if(a[tx][ty]==1&&v[tx][ty]==0&&tx>=0&&ty>=0)
		{
			v[tx][ty]=1;
			dfs(tx,ty,fx,fy);
			v[tx][ty]=0;
		}
		if(tx==fx&&ty==fy)	cnt++;
	}
}
int main()
{	int n,m,t,sx,sy,fx,fy;
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	while(t--)
	{
		int ax,ay;
		cin>>ax>>ay;
		a[ax][ay]=2;
	}
	dfs(sx,sy,fx,fy);	
	cout<<cnt;
	return 0;	
}
2024/3/5 12:48
加载中...