Title: http://www.lydsy.com/JudgeOnline/problem.php?id=3105
Test instructions is to take some number so that the remaining number of XOR and the subset is not 0
Quasi-array. Solve maximal linear independent groups. Greedy from large to small put, open 31 vectors to indicate the number of binary I-digit case, if a number can be represented by the previous number, then this number is not taken. Note Long long.
#include <cstring>#include<iostream>#include<algorithm>#include<cstdio>#defineMAXN 109#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#definell Long Longusing namespacestd;intn,m= to; ll ANS,SUM,A[MAXN],W[MAXN],BIN[MAXN];intRead () {intx=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) { if(ch=='-') f=-1; Ch=GetChar (); } while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar (); } returnx*F;}BOOLcmpintXinty) { returnX>y;}intMain () {n=read (); Rep (I,1, n) a[i]=read (), sum+=A[i]; Rep (I,1, m) bin[i]=1<< (I-1); Sort (a+1, A +1+n,cmp); Rep (I,1, N) { intnow=A[i]; Down (j,m,1)if(a[i]&Bin[j]) { if(W[j]) a[i]^=A[w[j]]; Else{W[j]=i; Break; } } if(A[i]) ans+=Now ; } if(ans!=0) printf ("%lld\n", sum-ans); ElsePuts"-1"); return 0;}
Bzoj 3105: [cqoi2013] New NIM game