30分求助
  • 板块P1605 迷宫
  • 楼主JYZHANG
  • 当前回复6
  • 已保存回复6
  • 发布时间2021/9/10 16:57
  • 上次更新2023/11/4 07:10:37
查看原帖
30分求助
403266
JYZHANG楼主2021/9/10 16:57
#include <iostream>
using namespace std;

bool map[6][6];
int m, n, t;
unsigned long long ans = 0;
short dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void dfs(int x, int y){
	if(x == n && y == n){
		ans++;
		return;
	}
	if(x < 1 || y < 1) return;
	if(x > n || y > n) return;
	if(map[x][y] == false) return;
	ans++;
	map[x][y] = false;
	
	for(int i=0; i<4; i++)
		dfs(x+dx[i], y+dy[i]);
	
	map[x][y] = true;
}

int main(){
	cin >> m >> n >> t;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
			map[i][j] = true;
	int x1, y1;
	while(t--){
		cin >> x1 >> y1;
		map[x1][y1] = false;
	}
	dfs(1, 1);
	cout << ans << endl;
	return 0;
} 
2021/9/10 16:57
加载中...