The
First gives a conclusion: if there are n piles of matches, each match has A1, A2, a3...an matches, under the rule of the traditional Nim game, if A1^a2^a3^...^an=0 will lose. And these two conclusions are completely equivalent, that is to say, if you do not meet this condition, you will win.
then in the subject, after picking up some matches, if the remaining matches have a subset of the match or 0, then the next hand to remove the other matches, leaving a different or a 0 of the state, so the tempo will fail.
So in order to prevent this, you can't have a subset that makes a subset different or 0, and you can do it with a linear base.
I don't know what the hell is a bunch of puzzle-writing on the web. I guess the feeling of greed + linear base is right ...
#include <cmath> #include <cstdio> #include <vector> #include <queue > #include <cstring> #include <iomanip> #include <stdlib.h> #include <iostream> #include < Algorithm> #define LL long #define INF 1000000000 #define MOD 1000000007 #define N 10000 #define FO (i,a,b) for (i=a
i<=b;i++) #define FD (I,A,B) for (i=a;i>=b;i--) using namespace std;
int n,i,j;
ll Sum,res;
int a[n],b[n],f[n];
int main () {scanf ("%d", &n);
Fo (i,1,n) scanf ("%d", &a[i]);
Sort (a+1,a+n+1);
FO (i,1,n) sum + = A[i], b[i] = a[i]; FD (i,n,1) {FD (j,29,0) if (A[i] >> j) & 1 if (!F[J) {F[j] = i; break;}
else A[i] ^= A[f[j]];
if (A[i]) res = = B[i]; if (res) printf ("%lld\n", sum-res);
else printf (" -1\n");
return 0; }