30分求助
  • 板块P1605 迷宫
  • 楼主Xuliuyi
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/22 21:16
  • 上次更新2024/5/23 09:57:00
查看原帖
30分求助
1046682
Xuliuyi楼主2024/5/22 21:16
#include<iostream>
using namespace std;
bool a[10][10];
bool b[10][10]={0};
int sx,sy,fx,fy,tx,ty;
const int xx[4]={0,0,1,-1};
const int yy[4]={-1,1,0,0};
int n,m,t,ans=0;
void dfs(int x,int y)
{
	if(x<1||y<1||x>n||y>m)
	{
		return;
	}
		
	if(x==fx&&y==fy)
	{
		ans++;
		return;
	}
	
	b[x][y]==true;
	for(int i=0;i<=3;i++)
	{
		if(b[x+xx[i]][y+yy[i]]==false&&a[x+xx[i]][y+yy[i]]==true)
		{
			dfs(x+xx[i],y+yy[i]);
		}
	}
	b[x][y]=false;
}
int main()
{
	
	cin>>n>>m>>t;
	cin>>sx>>sy>>fx>>fy;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			a[i][j]==true;
		}
	}
		
			
	for(int i=1;i<=t;i++)
	{
		cin>>tx>>ty;
		a[tx][ty]==false;
	}
	
	b[sx][sy]=true;
	dfs(sx,sy);
	cout<<ans;
	return 0;
}

输了样例,但是输出0

2024/5/22 21:16
加载中...