简略题意:
n
个物品,每个物品两个权值。
2.
价值
现在需要选出若干个物品,使得他们的编号亦或和不为
0
,且价值最大。
线性基中任意元素的亦或值均不为
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 63;
struct A{
LL id;
LL val;
bool operator < (const A & b) const {
return val < b.val;
}
};
vector<A> V;
int n;
LL a[maxn+1], id[maxn+1];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
LL x, y;
scanf("%lld%lld", &x, &y);
V.push_back({x, y});
}
sort(V.begin(), V.end());
for(int i = V.size() - 1; i >= 0; i--) {
for(int j = maxn; j >= 0; j--) {
if(V[i].id & (1LL << j)) {
if(a[j])
V[i].id ^= a[j];
else {
a[j] = V[i].id, id[j] = i;
break;
}
}
}
}
LL ans = 0;
for(int i = maxn; i >= 0; i--)
if(a[i])
ans += V[id[i]].val;
printf("%lld\n", ans);
return 0;
}