[bzoj2460][BJOI2011]元素

只有0-1的高斯消元法,还是挺简单的

#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,ans;
pair<int,LL> a[1001];
LL s[64];

inline bool ins(LL x){
    for(int i=0;x!=0;i++) if(x&(1LL<<i)){
        if(s[i]==0) {
            s[i]=x; return 1;
        }
        else x^=s[i];
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i].second>>a[i].first;
    sort(a,a+n);
    for(int i=n-1;i>=0;i--) if(ins(a[i].second)) ans+=a[i].first;
    cout<<ans<<endl;
    return 0;
}

 

posted @ 2016-01-06 10:42  海豚爸爸  阅读(308)  评论(0编辑  收藏  举报