Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
3
Indexable
#include<iostream>
using namespace std;

int T, n, r, svt, sk;
int vt[105][2], k[105][3], visit[105];
int rs, flag;

void nhap(){
	cin >> n >> r;
	cin >> svt;
	for(int i = 0; i < svt; i ++) cin >> vt[i][0] >> vt[i][1];
	cin >> sk;
	for(int i = 0; i < sk; i ++) {cin >> k[i][0] >> k[i][1] >> k[i][2]; visit[i] = 0;}
}

int abs(int x) {
	if(x > 0) return x;
	return -x;
}

int process(int a) {
	int sum = 0;
	int x = vt[a][0], y = vt[a][1];
	for(int i = 0; i < sk; i ++) {
		int xx = abs(x-k[i][0]), yy = abs(y-k[i][1]);
		int kc = xx*xx + yy*yy;
		if(kc <= r*r && !visit[i]) {
			visit[i] = 1;
			sum += k[i][2];
		}
	}
	return sum;
}

void dequy(int gg=0,int count=0, int j = 0) {
	if(gg==n) {
		if(count > rs) rs = count;
		return;
	}
	int vs[105];
	for(int i = j; i < svt; i ++) {
		for(int i = 0; i < sk; i ++) vs[i] = visit[i];
		dequy(gg+1, count + process(i), i+1);
		for(int i = 0; i < sk; i ++) visit[i] = vs[i];
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> T;
	for(int t = 1; t <= T; t ++) {
		nhap();
		rs = 0;
		dequy();
		cout << "#" << t << " " << rs << endl;
		//cout << process(0);
	}
	return 0;
}