#2019120500006-LG 迷宫

(P1605)

做题历程:
搜索从(map[1][1])开始,起点(map[sx][sy])没标记,洛谷(80)分(数据真水)

实际上搜索不加(map[sx][sy])的标记,回溯到起点的时候判断条件还是成立,会继续回溯到起点之前的点,结果会大很多

至于审题的问题还是要注意,虽然骗了(80)

//100pts
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int cnt=0,N,M,T,sx,sy,fx,fy;
int map[7][7];
int x[6]= {0,1,-1,0,0};
int y[6]= {0,0,0,-1,1};
bool ifborder(int x1,int y1)
{
	return (x1>M||x1<1||y1>N||y1<1);
}
void dfs(int x1,int y1)
{
	if(x1==fx&&y1==fy)
	{
		cnt++;
		return ;
	}
	for(int i=1; i<=4; i++)
	{
		int xp=x1+x[i];
		int yp=y1+y[i];
		if(map[xp][yp]==0&&!ifborder(xp,yp))
		{
			map[xp][yp]=1;
			dfs(xp,yp);
			map[xp][yp]=0;
		}
	}
}
int main()
{
	memset(map,0,sizeof(map));
	scanf("%d%d%d",&N,&M,&T);
	scanf("%d%d%d%d",&sx,&sy,&fx,&fy);
	for(int i=1; i<=T; i++)
	{
		int p,q;
		scanf("%d%d",&p,&q);
		map[p][q]=1;
	}
	map[sx][sy]=1;
	dfs(sx,sy);
	printf("%d",cnt);
	return 0;
}
要做就做南波万
原文地址:https://www.cnblogs.com/liuziwen0224/p/11992317.html