MLE 求助
查看原帖
MLE 求助
826246
Placy楼主2023/6/25 19:48
#include <map>
#include <iostream>
#define int long long
using namespace std;
int n, tx, ty;
int ans[41];
struct Node {int x, y;}a[41];
struct W {
	int x, y, s;
	bool operator < (const W &u) const {return x < u.x || x == u.x && y < u.y || x == u.x && y == u.y && s < u.s;}
};
map <W, int> m1, m2;
void dfs1 (int cnt, int x, int y, int s) {
	if (cnt == n / 2 + 1) {
		++ m1[W{x, y, s}];
		return;
	}
	dfs1 (cnt + 1, x + a[cnt].x, y + a[cnt].y, s + 1);
	dfs1 (cnt + 1, x, y, s);
}
void dfs2 (int cnt, int x, int y, int s) {
	if (cnt == n + 1) {
		++ m2[W{x, y, s}];
		return;
	}
	dfs2 (cnt + 1, x + a[cnt].x, y + a[cnt].y, s + 1);
	dfs2 (cnt + 1, x, y, s);
}
signed main () {
	cin >> n >> tx >> ty;
	for (int i = 1; i <= n; i ++) cin >> a[i].x >> a[i].y;
	dfs1 (1, 0, 0, 0);
	dfs2 (n / 2 + 1, 0, 0, 0);
	for (auto u : m1) {
		int nx = tx - u.first.x, ny = ty - u.first.y, mk = n - u.first.s;
		for (int s = 0; s <= mk; s ++) ans[s + u.first.s] += u.second * m2[{nx, ny, s}];
	}
	for (int i = 1; i <= n; i ++) {
		cout << ans[i] << "\n";
	}
	return 0;
}
2023/6/25 19:48
加载中...