30分,连样例都过不了
查看原帖
30分,连样例都过不了
1068513
ZHUSITAOcccccc楼主2024/8/28 19:16
#include <bits/stdc++.h>
#define int long long int
using namespace std;
inline int read() {
	register int x = 0, f = 1;
	register char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-')
			f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
inline void write(int x) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}
int n, m, t, sx, sy, fx, fy, ox, oy, nx, ny, ans, maps[10][10], flag[10][10], dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
void dfs(int x, int y) {
	if (x == fx && y == fy) {
		ans++;
		return ;
	}
	for (int i = 0; i < 4; i++) {
		nx = x + dx[i], ny = y + dy[i];
		if (nx > 0 && nx <= fx && ny > 0 && ny < fy && maps[nx][ny] && !flag[nx][ny]) {
			flag[nx][ny] = 1;
			dfs(nx, ny);
			flag[nx][ny] = 0;
		}
	}
}
main() {
	ios::sync_with_stdio(false);
	memset(maps, 1, sizeof maps);
	n = read();
	m = read();
	t = read();
	sx = read();
	sy = read();
	fx = read();
	fy = read();
	while (t--) {
		ox = read();
		oy = read();
		maps[ox][oy] = 0;
	}
	dfs(sx, sy);
	write(ans);
}
2024/8/28 19:16
加载中...