bzoj2460,戳我戳我
Solution:
- 线性基板子,没啥好说的,注意long long 就好了
Code:
//It is coded by Ning_Mew on 5.29
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1007;
int n;
LL A[maxn];
struct Node{
LL num;int val;
}s[maxn];
LL ans=0;
bool cmp(const Node &x,const Node &y){return x.val>y.val;}
bool check(int k){
bool kk=false;
for(int i=60;i>=0;i--){
if((s[k].num>>i)&1){
if(!A[i]){
A[i]=s[k].num; kk=true; break;
}else{
s[k].num=(s[k].num^A[i]);
}
}
}return kk;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld%d",&s[i].num,&s[i].val);
}
sort(s+1,s+n+1,cmp);
for(int i=1;i<=n;i++){
if(check(i))ans+=s[i].val;
}
printf("%lld
",ans);
return 0;
}