#3#4TLE求助!!!
查看原帖
#3#4TLE求助!!!
565707
mediocre_楼主2022/9/4 10:06
#include<bits/stdc++.h>
using namespace std;
int sx, sy, px, py, ans = 0;
bool a[1005][1005];
int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar();
	}
	return x * f;
}
void dfs(int x, int y) {
	if (x == sx && y == sy) {
		++ans;
		return;
	}
	if (x <= sx && y <= sy && a[x + 3][y + 3] == false) {
		dfs(x + 1, y);
		dfs(x, y + 1);
	}
}
int main() {
	sx = read();
	sy = read();
	px = read();
	py = read();
	a[px + 3][py + 3] = true;
	a[px - 2 + 3][py - 1 + 3] = true;
	a[px - 2 + 3][py + 1 + 3] = true;
	a[px - 1 + 3][py - 2 + 3] = true;
	a[px - 1 + 3][py + 2 + 3] = true;
	a[px + 1 + 3][py - 2 + 3] = true;
	a[px + 1 + 3][py + 2 + 3] = true;
	a[px + 2 + 3][py - 1 + 3] = true;
	a[px + 2 + 3][py + 1 + 3] = true;
	dfs(0, 0);
	printf("%d", ans);
	return 0;
}
2022/9/4 10:06
加载中...