跪求大佬指点,卡70ptsWA
  • 板块P1605 迷宫
  • 楼主Matheart
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/9/12 17:38
  • 上次更新2024/9/12 21:09:37
查看原帖
跪求大佬指点,卡70ptsWA
600155
Matheart楼主2024/9/12 17:38

很奇怪为什么是这样,大部分都能过

#include <bits/stdc++.h>
using namespace std;
int n,m,t;
int ans;
int sx,sy,fx,fy;
bool a[15][15];
int dx,dy;
void dfs(int x, int y)
{
	if(x==fx&&y==fy){
		ans++;
		return;
	}
	if(a[x+1][y]==false)
	{
		a[x+1][y]=true;
		dfs(x+1,y);
		a[x+1][y]=false;
	}
	if(a[x][y+1]==false)
	{
		a[x][y+1]=true;
		dfs(x,y+1);
		a[x][y+1]=false;
	}
	if(a[x-1][y]==false)
	{
		a[x-1][y]=true;
		dfs(x-1,y);
		a[x-1][y]=false;
	}
	if(a[x][y-1]==false)
	{
		a[x][y-1]=true;
		dfs(x,y-1);
		a[x][y-1]=false;
	}
	return;
}
int main(){
	memset(a,true,sizeof(a));
	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]=false;
		}
	}
	for(int i=1;i<=t;i++){
		cin>>dx>>dy;
		a[dx][dy]=true;
	}
	dfs(sx,sy);
	cout<<ans<<endl;
	return 0;
}
2024/9/12 17:38
加载中...