题面
Sol
就是选出一些石头,最大化价值,使得这些石头的任意非空子集的标号异或和不为\(0\)
而它的线性基任意非空子集的异或和的值域和它是一样的
那么我们按价值从大到小加入线性基,判断是否存在就好了
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
# define Copy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1005);
IL ll Input(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n;
struct Stone{
ll p, w;
IL bool operator <(RG Stone B) const{
return w > B.w;
}
} a[_];
ll ans;
ll b[63], pw[63] = {1};
int main(RG int argc, RG char* argv[]){
n = Input();
for(RG int i = 1; i < 63; ++i) pw[i] = pw[i - 1] << 1;
for(RG int i = 1; i <= n; ++i) a[i].p = Input(), a[i].w = Input();
sort(a + 1, a + n + 1);
for(RG int i = 1; i <= n; ++i){
for(RG int j = 62; ~j; --j){
if(~a[i].p & pw[j]) continue;
if(!b[j]){
b[j] = a[i].p;
break;
}
a[i].p ^= b[j];
if(!a[i].p) break;
}
if(a[i].p) ans += a[i].w;
}
printf("%lld\n", ans);
return 0;
}