1. 程式人生 > >【題解】 bzoj2460: [BeiJing2011]元素 (線性基)

【題解】 bzoj2460: [BeiJing2011]元素 (線性基)

pan it is scan bzoj AS names 線性 solution check

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\n",ans); return 0; }

【題解】 bzoj2460: [BeiJing2011]元素 (線性基)