题目:
题解:
求极大线性无关向量组,并且权值尽量大
按照权值从大到小排序,贪心用高斯消元求解线性基
代码:
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
struct hh{int w;LL num;}a[1005];
LL b[70];
int cmp(hh a,hh b){return a.w>b.w;}
int main()
{
int n;scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%lld%d",&a[i].num,&a[i].w);
sort(a+1,a+n+1,cmp);
for (int i=1;i<=n;i++)
for (int j=60;j>=0;j--)
if (a[i].num>>j&1)
{
if (!b[j]) {b[j]=i;break;}
else a[i].num^=a[b[j]].num;
}
LL ans=0;
for (int i=60;i>=0;i--) ans+=a[b[i]].w;
printf("%lld",ans);
}