【题目分析】
线性基,由于最多有63个,只需要排序之后,动态的去维护线性基即可。
【代码】
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <set> #include <map> #include <string> #include <algorithm> #include <vector> #include <iostream> #include <queue> using namespace std; #define maxn 10005 #define ll long long int read() { int x=0,f=1; char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();} while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();} return x*f; } ll lb[65]; struct node{ll n;int w;}a[maxn]; bool cmp(node a,node b) {return a.w>b.w;} int main() { int n=read(); int ans=0; for (int i=1;i<=n;++i) scanf("%lld%d",&a[i].n,&a[i].w); sort(a+1,a+n+1,cmp); for (int i=1;i<=n;++i) { for (int j=63;j>=0;--j) { if ((a[i].n>>j)&1) { if (!lb[j]) {lb[j]=a[i].n; break;} else a[i].n^=lb[j]; } } if (a[i].n) ans+=a[i].w; } printf("%d\n",ans); }