Problem Descriptionmatt has N friends. They is playing a game together.
Each of the Matt ' s friends has a magic number. In the game, Matt selects some (could is zero) of his friends. If the XOR (exclusive-or) sum of the selected friends ' magic numbers is no less than M, Matt wins.
Matt wants to know the number of ways to win.
Inputthe first line contains only one integer T, which indicates the number of test cases.
For each test case, the first line contains the integers N, M (1≤n≤40, 0≤m≤106).
In the second line, there is N integers ki (0≤ki≤106), indicating the i-th friend ' s magic number.
Outputfor each test case, output A, "case #x: Y", where x was the case number (starting from 1) and Y indicates The number of ways where Matt can win.
Sample Input23 21 2 33 31 2 3
Sample outputcase #1:4Case #2:2
Test instructions: gives the number of n, and the number of M in n number of numbers by XOR or operation.
Idea: Set DP[I][J] to the number of the first I number of different or J, Dp[i][j]=dp[i-1][j]+dp[i-1][j^a[i]]; this dp[i-1][j] very easy to understand, do not explain, for Dp[i-1][j^a[i]], because J^a[i] ^a[i]=j, so j^a[i] is the number of the first i-1 in the number of different or can to J.
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Long Longdp[3][2000006];6 intMain ()7 {8 Long Longt,n,m,i,j,k=1;9 Long Longans;Ten inta[ -]; Onescanf"%i64d",&t); A while(t--) - { -scanf"%i64d%i64d",&n,&m); the for(i=1; i<=n;i++) scanf ("%i64d",&a[i]); -Memset (DP,0,sizeof(DP)); -dp[0][0]=1; - for(i=1; i<=n;i++) + { - for(j=0; j<=2000004; j + +) +dp[i%2][j]=dp[(I-1)%2][j]+dp[(I-1)%2][j^A[i]]; A } atans=0; -n=n%2; - for(i=m;i<=1400000; i++) ans+=Dp[n][i]; -printf"Case #%i64d:%i64d\n", K,ans); -k++; - } in}
Hdu 5119 Happy Matt Friends (DP)