bzoj3105

http://www.lydsy.com/JudgeOnline/problem.php?id=3105

就是不懂。。。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
int n;
ll tot;
ll a[N], bin[40], b[N];
bool cp(ll x, ll y) { return x > y; }
int main()
{
    bin[0] = 1; for(int i = 1; i <= 30; ++i) bin[i] = bin[i - 1] * 2;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), tot += a[i];
    sort(a + 1, a + n + 1, cp);
    for(int i = 1; i <= n; ++i)
    {
        ll t = a[i];
        for(int j = 30; j >= 0; --j) if(a[i] & bin[j])
        {
            if(!b[j]) { b[j] = i; break; }
            else a[i] ^= a[b[j]];
        }
        if(a[i]) tot -= t;
    }
    printf("%lld\n", tot);
    return 0;
} 
View Code

 

posted @ 2017-05-10 17:14  19992147  阅读(136)  评论(0编辑  收藏  举报