Transmission: https://www.luogu.org/problem/P4570
Meaning of the questions: Given a number of items, each item has two properties, the magic number and value now selected a few of these items, select the required number of items it can not be the exclusive or the magic of 0 and maximum value add up, find out of this maximum.
analysis:
Given the nature of a linear group: the same number of linear groups is the same set of elements.
So greedy consider the answer. If the current item number to be inserted, then the answer is contributing.
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn=1010; 5 struct node{ 6 ll x,y; 7 }a[maxn]; 8 bool cmp(node p,node q){return p.y>q.y;} 9 struct Linear_basis{ 10 ll b[65],tot; 11 bool insert(ll x){ 12 for (int i=60; I> = 0 ; i-- ) { 13 is IF (X & (1LL << I)) { 14 IF (! B [I]) { 15 B [I] = X; BREAK ; 16 } . 17 X ^ = B [I]; 18 is } . 19 } 20 is return X> 0 ; // if insertable true: insertable, false: not insert 21 is } 22 is } an LB; 23 is int main () { 24 int n-; Scanf ( " % D " , &n); ll x; 25 for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i].x,&a[i].y); 26 sort(a+1,a+1+n,cmp); 27 ll ans=0; 28 for (int i=1;i<=n;i++){ 29 bool f=LB.insert(a[i].x); 30 if (f) ans+=a[i].y; 31 } 32 printf("%lld\n",ans); 33 Return 0 ; 34 }