40分,求救,哪里错了
  • 板块P1605 迷宫
  • 楼主weichen123
  • 当前回复10
  • 已保存回复10
  • 发布时间2022/8/19 20:09
  • 上次更新2023/10/27 14:33:07
查看原帖
40分,求救,哪里错了
657500
weichen123楼主2022/8/19 20:09
#include<bits/stdc++.h>
using namespace std;
int n, m, t;
int sx, sy, fx, fy, ans;
int a[101][101];
bool temp[101][101];
int l, r;
int tx, ty;
int qx[5] = {0, 0, 1, 0, -1};
int qy[5] = {0, 1, 0, -1, 0};
void dfs(int x, int y) {
	if (x == fx && y == fy) {
		ans++;
		return;	
	} else {
		for (int i = 1; i <= 4; i++) {
			tx = qx[i] + x;
			ty = qy[i] + y;
			if (temp[tx][ty] == 0 && ! a[l][r] && !temp[l][r]) {
				temp[tx][ty] = 1;
				dfs(tx, ty);
				temp[tx][ty] = 0;
			}
		}
	}
}
int main() {
	//freopen("name.in","r",stdin);
	//freopen("name.out","w",stdout);
	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] = 1;
		}
	}
	a[sx][sy] = 1;

	for (int i = 1; i <= t; i++) {
		cin >> l >> r;
		a[l][r] = 1;
	}
	dfs(sx, sy);
	cout << ans;
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}
2022/8/19 20:09
加载中...