求救,为什么只有 50分啊?
查看原帖
求救,为什么只有 50分啊?
1279073
nowornever0625楼主2024/10/1 09:10
#include <bits/stdc++.h>
using namespace std;
int n, m, t, sx, sy, fx, fy, nx, ny, cnt = 0;
int Map[6][6];
bool vis[6][6];

int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

void dfs(int x, int y) {
	if (x == fx && y == fy) {
		cnt++;
		return;
	} else {
		for (int i = 0; i < 4; i++) {
			nx = x + dir[i][0], ny = y + dir[i][1];
			if (nx > 0 && nx <= n && ny > 0 && ny <= m) {
				if (vis[nx][ny] == 0 && Map[nx][ny] == 1) {
					vis[nx][ny] = 1;
					dfs(nx, ny);
					vis[nx][ny] = 0;
				}
			}
		}

	}
}
int main() {
	//freopen("tmp.in", "r", stdin);
	scanf("%d%d%d", &n, &m, &t);
	scanf("%d%d%d%d", &sx, &sy, &fx, &fy);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			Map[i][j] = 1;
	while (t--) {
		int i, j;
		cin >> i >> j;
		Map[i][j] = 0;
	}
	vis[sx][sy] = 1;
	dfs(sx, sy);
	cout << cnt << endl;
	return 0;
}
2024/10/1 09:10
加载中...