我解释一下,你要枚举你选出来的状态,如果总的^为sum,这一部分同样为sum,那么剩下的就是0了
链接:https://www.nowcoder.com/acm/contest/123/G
来源:牛客网空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld
题目描述
Alice and Bob are playing a stone game. There are n piles of stones. In each turn, a player can remove some stones from a pile (the number must be positive and not greater than the number of remaining stones in the pile). One player wins if he or she remove the last stone and all piles are empty. Alice plays first.
To make this game even more interesting, they add a new rule: Bob can choose some piles and remove entire of them before the game starts. The number of removed piles is a nonnegative integer, and not greater than a given number d. Note d can be greater than n, and in that case you can remove all of the piles.
Let ans denote the different ways of removing piles such that Bob are able to win the game if both of the players play optimally. Bob wants you to calculate the remainder of ans divided by109+7.
输入描述:
The first line contains an integer T, representing the number of test cases. For each test cases, the first line are two integers n and d, which are described above. The second line are n positive integersai, representing the number of stones in each pile.
输出描述:
For each test case, output one integer (modulo109+7.) in a single line, representing the number of different ways of removing piles that Bob can ensure his victory.
输入
2 5 2 1 1 2 3 4 6 3 1 2 4 7 1 2
输出
2 5
#define happy
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define pll pair<ll,ll>
#define vi vector<int>
#define P pair<int,int>
#define pb push_back
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
ll rd(){
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;
}
const int N=1e3+30;
int dp[N][12][N];
ll a[N];
int main(){
#ifdef happy
freopen("in.txt","r",stdin);
#endif
int t=rd();
while(t--){
int n=rd(),d=rd();
memset(dp,0,sizeof(dp));
int sum=0;
rep(i,1,n){
a[i]=rd();
sum^=a[i];
}
dp[0][0][0]=1;
rep(i,1,n){
dp[i][0][0]=1;
rep(j,1,d)rep(k,0,1024){
dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k^a[i]];
if(dp[i][j][k]>=mod)
dp[i][j][k]-=mod;
}
}
ll ans=0;
rep(i,0,d){
// printf("%d\n",dp[n][i][sum]);
ans+=dp[n][i][sum];
if(ans>=mod)ans-=mod;
}
printf("%lld\n",ans);
}
}