题面
Sol
也是拿出一些数,使剩下的异或起来不为(0)
而线性基内的数异或不出(0)
那么从大到小加到线性基内
然后中途为(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, a[_];
ll ans;
int b[31], pw[31] = {1};
IL int Cmp(RG int x, RG int y){
return x > y;
}
int main(RG int argc, RG char* argv[]){
n = Input();
for(RG int i = 1; i < 31; ++i) pw[i] = pw[i - 1] << 1;
for(RG int i = 1; i <= n; ++i) a[i] = Input();
sort(a + 1, a + n + 1, Cmp);
for(RG int i = 1; i <= n; ++i){
RG int x = a[i];
for(RG int j = 31; ~j; --j){
if(~x & pw[j]) continue;
if(!b[j]){
b[j] = x;
break;
}
x ^= b[j];
if(!x) break;
}
if(!x) ans += a[i];
}
printf("%lld
", ans);
return 0;
}