萌新求助嘤嘤嘤
查看原帖
萌新求助嘤嘤嘤
84121
_FILARET_楼主2020/11/13 20:31
#include <bits/stdc++.h>
using namespace std;
const int maxn = 18 + 5;
const int maxs = (1 << 18) + 5;
bool eql(double dx, double dy) {
	double eps = 1e-6;
	if(abs(dx - dy) < eps) return true;
	return false;
}
int t, n, m, dp[maxs], kill[maxn][maxn];
pair<double, double> pig[maxn];
void init(int x, int y) {
	double A, B, xx, xy, yx, yy;
	xx = pig[x].first; xy = pig[x].second;
	yx = pig[y].first; yy = pig[y].second;
	A = (yx * xy - xx * yy) / (xx - yx) / (xx * yx);
	B = (xx * xx * yy - yx * yx * xy) / (xx - yx) / (xx * yx);
	for(int i = 1 ; i <= n ; i ++) {
		xx = pig[i].first; yy = pig[i].second;
		if(eql(yy, A * xx * xx + B * xx))
			kill[x][y] += (1 << (i - 1));
	}
	return;
}
int DP(int op) {
	//cout << op << endl;
	if(dp[op] != 0x3f3f3f3f) return dp[op];
	int ret = dp[op];
	for(int i = 1 ; i <= n ; i ++)
		if(!((op >> (i - 1)) & 1)) {
			//cout << "kill single on " << op << ": killed " << i << endl;
			//cout << "after killing: " << (op + (1 << (i - 1))) << endl;
			ret = min(ret, DP(op + (1 << (i - 1))) + 1);
		}
	for(int i = 1 ; i <= n ; i ++) {
		for(int j = i + 1 ; j <= n ; j ++) {
			if(eql(pig[i].first, pig[j].first)) continue;
			int opp = kill[i][j];
			ret = min(ret, DP((op | opp)) + 1);
		}
	}
	return dp[op] = ret;
}
int main() {
	scanf("%d", &t);
	while(t --) {
		scanf("%d%d", &n, &m);
		for(int i = 1 ; i <= n ; i ++)
			scanf("%lf%lf", &pig[i].first, &pig[i].second);
		memset(dp, 0x3f, sizeof(dp));
		memset(kill, 0, sizeof(kill));
		dp[(1 << n) - 1] = 0;
		for(int i = 1 ; i <= n ; i ++)
			for(int j = i + 1 ; j <= n ; j ++) {
				if(eql(pig[i].first, pig[j].first)) continue;
				init(i, j);
			}
		for(int op = 0 ; op <= 2 ; op ++) {
			for(int i = 1 ; i <= n ; i ++)
				if(!((op >> (i - 1)) & 1)) {
					//cout << op << "->" << op + (1 << (i - 1)) << endl;
				}
			for(int i = 1 ; i <= n ; i ++) {
				for(int j = i + 1 ; j <= n ; j ++) {
					if(eql(pig[i].first, pig[j].first)) continue;
					int opp = kill[i][j];
					//cout << op << "->" << (op | opp) << endl;
				}
			}
		}
		printf("%d\n", DP(0));
	}
	return 0;
}

样例2 WA+RE

2020/11/13 20:31
加载中...