linkkkk
题意:
Nim游戏,任取几堆石子使得先手必败,问有几种方案数。
思路:
跟上题类似
方案数就是
2
自
由
元
个
数
2^{自由元个数}
2自由元个数
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
typedef pair<string,string>PSS;
#define I_int ll
inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
ll ksm(ll a, ll b,ll mod){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
const int maxn=2010,mod=1e9+7;
const double pi = acos(-1);
ll n,m=31;
ll a[110][110],g[110];
int Gauss(int n,int m)
{
int r, c;
for(r = 0, c = 0; c < n; c++)
{
int t = -1;
for(int i = r; i < m; i++)
{
if(a[i][c])
{
t = i;
break;
}
}
if(t==-1) continue;
for(int i = c; i < n; i++)///交换
{
swap(a[t][i], a[r][i]);
}
for(int i = r + 1; i < m; i++)
{
if(a[i][c])
for(int j = c; j <n; j++)
{
a[i][j] = a[i][j] ^ a[r][j];
}
}
r++;
}
return n-r;
/*if(r < n)
{
for(int i = r; i < n; i++)
{
if(a[i][n]) return 2;
}
return 1;
}
for(int i = n - 1; i >= 0; i--)
{
for(int j = i + 1; j < n; j++)
{
if(a[i][j])
a[i][n] ^= a[j][n];
}
}
return 0;*/
}
void solve()
{
cin >> n;
for(int i=0;i<n;i++) cin>>g[i];
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=(g[j]>>i)&1;
int ans=Gauss(n,m);
ll mod=1000007;
cout<<ksm(2,ans,mod)<<endl;
}
int main()
{
int _;cin>>_;
while(_--) solve();
return 0;
}