http://acm.hdu.edu.cn/showproblem.php?pid=3949
This problem has been done three times, but has been not very understand, today and understand again, is to let you select some of the n numbers, different or up to get some value, and then ask what the small number of K can get.
First of all, each number is considered binary, then the Gauss elimination, if this is 1, put the other one is 1 of the elements are different or it, eliminate 1, so that a bit of 1 only one, and then get a k, that is, after the elimination of only K 1, can be composed of 2k 2^k number, And then it's about the n elements, each element is the original number of different or obtained values, so you can directly combine, consider some special circumstances, that is, if the k=n, so that each number has a 1, then it is absolutely impossible to take 0, then the number that can be composed of 2k−1 2^ K-1 A, and then ask you the K small, direct is to see the binary system of K, which has 1, the linear base inside from small to large that 1 different or up on the line.
Code:
#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include & lt;string> #include <vector> #include <cstdio> #include <cctype> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #pragma comment (linker, "
/stack:102400000,102400000 ") using namespace std; #define MAX 10005 #define MAXN 1000005 #define MAXNODE #define Sigma_size #defin E lson l,m,rt<<1 #define Rson m+1,r,rt<<1|1 #define LRT rt<<1 #define RRT rt<<1|1 #define Middle int m= (r+l) >>1 #define LL Long #define Ull unsigned long long #define MEM (x,v) memset (x,v,sizeof (x)) #define LOWBIT (x) (x&-x) #define P II Pair<int,int> #define BITS (a) __builtin_popcount (a) #define MK Make_pair #define LIMIT 10000//const int prime = 999983;
const int INF = 0X3F3F3F3F;
Const LL INFF = 0x3f3f;
Const double PI = ACOs (-1.0);
Const double inf = 1E18;
Const double EPS = 1e-4;
Const LL mod = 1e9+7;
Const ULL MX = 133333331;
/*****************************************************/inline void RI (int &x) {char C;
while ((C=getchar ()) < ' 0 ' | | c> ' 9 ');
x=c-' 0 ';
while ((C=getchar ()) >= ' 0 ' && c<= ' 9 ') x= (x<<3) + (x<<1) +c-' 0 ';
}/*****************************************************/LL A[max];
int n;
int Gauss () {int k=1;
for (int i=63;i>=0;i--) {int t=0;
for (int j=k;j<=n;j++) {if ((a[j]>>i) &1) {t=j;
Break
} if (t) {swap (a[k],a[t]);
for (int j=1;j<=n;j++) {if (j!=k&& (a[j]>>i) &1) a[j]^=a[k];
} k++;
} return k-1;
int main () {//freopen ("In.txt", "R", stdin);
int t,kase=0;
cin>>t;
while (t--) {cin>>n;
kase++;
printf ("Case #%d:\n", Kase);
for (int i=1;i<=n;i++) scanf ("%i64d", &a[i));
int Cnt=gauss ();
LL tmp= (1ll<<cnt);
if (cnt==n) tmp--;
int k;
cin>>k;
while (k--) {LL x;
scanf ("%i64d", &x);
if (x>tmp) printf (" -1\n");
else{if (n>cnt) x--;
LL ans=0;
for (int i=0;i<cnt;i++) {if ((x>>i) &1) ans^=a[cnt-i];
printf ("%i64d\n", ans);
}} return 0; }