70分求助!
  • 板块P1605 迷宫
  • 楼主cyhyeee
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/7/20 20:32
  • 上次更新2023/11/3 08:34:33
查看原帖
70分求助!
973237
cyhyeee楼主2023/7/20 20:32
#include <bits/stdc++.h>
using namespace std;
int n, m, t, sx, sy, zx, zy, ax, ay, ans, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}, v[1000][1000],q[1000][1000];

void dfs(int x, int y) {
	cout << x << " " << y << endl;
	if (x == zx && y == zy) {
		ans++;
		cout << endl;
		return;
	}
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx >= 1 && ny >= 1 && nx <= n && ny <= m && q[nx][ny] == 0 && v[nx][ny] == 0) {
			v[nx][ny] = 1;
			dfs(nx, ny);
			v[nx][ny] = 0;
		}
	}
}

int main() {
	cin >> n >> m >> t;
	cin >> sx >> sy >> zx >> zy;
	for (int i = 0; i < t; i++) {
		cin >> ax >> ay;
		q[ax][ay] = 1;
	}
	dfs(sx, sy);
	cout << ans;
	return 0;
}
2023/7/20 20:32
加载中...