Topic links:
The meaning of problems
Given \ (n-\) th ore, ore each value of the magic number has two properties and selecting a number of minerals, such that the maximum value of the magic number, and the exclusive OR is not zero.
Thinking
Linear yl greedy
According to the value of the magic ore descending order.
All XOR and linear group is not zero. Thus maintaining a linear group, each insert number \ (I \) , if the \ (I \) prior linear groups are linearly independent, which is to be inserted, is inserted and the magic value to a \ (ANS \) .
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
const int maxbit = 63;
struct M {
ll number, magic;
}m[maxn];
int cmp(M a, M b) {
return a.magic > b.magic;
}
ll p[maxbit];
bool judge(ll x) {
for(int i = maxbit - 1; i >= 0; --i) {
if((x >> i) & 1) {
if(p[i] == 0) {
p[i] = x;
break;
}
x ^= p[i];
}
}
if(x) {
return true;
} else {
return false;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> m[i].number >> m[i].magic;
}
sort(m, m + n, cmp);
ll ans = 0;
for(int i = 0; i < n; ++i) {
if(judge(m[i].number)) {
ans += m[i].magic;
}
}
cout << ans << endl;
return 0;
}