30wa求助大佬
  • 板块P1605 迷宫
  • 楼主Wang_H_S_
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/23 16:57
  • 上次更新2024/8/23 17:43:33
查看原帖
30wa求助大佬
1286601
Wang_H_S_楼主2024/8/23 16:57
#include<bits/stdc++.h>
using namespace std;
bool a[6][6], b[6][6];
int c[4] = {0, 0, 1, -1};
int d[4] = {-1, 1, 0, 0};
int n, m, sx, sy, fx, fy, x, y, ans = 0, t;
void dfs(int x, int y) {
	if (x == sx and y == fy) {
		ans++;
		return;
	} else {
		for (int i = 0; i <= 3; i++) {
			int ex = x + c[i];
			int ey = y + d[i];
			if (ex >= 0 and ex<n and ey >= 0 and ey < m and b[ex][ey] == 0 && a[ex][ey] == 0) {
				b[ex][ey] = 1;
				dfs(ex, ey);
				b[ex][ey] = 0;
			}
		}
	}
}
int main() {
	cin >> n >> m >> t;
	cin >> sx >> sy >> fx >> fy;
	sx -= 1, sy -= 1, fx -= 1, fy -= 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			a[i][j] = 0;
		}
	}
	for (int i = 0; i < t; i++) {
		int zx, zy;
		cin >> zx >> zy;
		a[zx - 1][zy - 1] = 1;
	}
	dfs(sx, sy);
	cout << ans;
	return 0;
}
2024/8/23 16:57
加载中...