链接 :https://www.lydsy.com/JudgeOnline/problem.php?id=2460
思路 :线性基不唯一,所以排序 进行贪心选择,价值最大的线性基,
#includeusing namespace std;#define ll long long#define maxn 123ll n,ans,p[maxn];struct node{ ll a,b; bool operator<(const node &c)const { return b>c.b; }} ss[maxn];void getji(ll x,int id){ for(int i=62; i>=0; i--) { if(!(x>>(ll)i)) continue; if(!p[i]) { p[i]=x; break; } x^=p[i]; } if(x!=0)ans+=ss[id].b;}int main(){ scanf("%lld",&n); for(int i=1; i<=n; i++) scanf("%lld%lld",&ss[i].a,&ss[i].b); sort(ss+1,ss+n+1); for(int i=1; i<=n; i++) getji(ss[i].a,i); printf("%lld\n",ans); return 0;}