Happy Matt Friends
Time limit:6000/6000 MS (java/others) Memory limit:510000/510000 K (java/others)
Total submission (s): Accepted submission (s): 270
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 Input
23 21 2 33 31 2 3
Sample Output
Case #1:4Case #2:2Hintin the. RST sample, Matt can win by Selecting:friend with number 1 and friend with number 2. The XOR sum is 3.friend with number 1 and friend with number 3. The XOR sum is a 2.friend with number 2. The XOR sum is a 2.friend with number 3. The XOR sum is 3. Hence, the answer is 4.
SOURCE2014ACM/ICPC Asia Beijing Station-Replay (thanks to the North Division and handing in)
Test instructionsThere are n people, each one has a weight, you can pick any number of people and their weights or (can not choose), the last to obtain a value of not less than the number of M.
DP[I][J]: In the first I personally selected, the method of the results of J how many kinds of
DP[I][J]=DP[I-1][J^VAL[I]]+DP[I-1][J]
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace Std;long long dp[2][1<<20];int val[50];int main () {int T; cin>>t; for (int cs=1;cs<=t;cs++) {int n,m; cin>>n>>m; for (int i=1;i<=n;i++) cin>>val[i]; int len=1<<20; Memset (Dp,0,sizeof (DP)); Dp[0][0]=1; for (int i=1;i<=n;i++) for (int j=0;j<len;j++) dp[i&1][j]=dp[(i-1) &1][j]+dp[(i-1) &am P;1][j^val[i]]; Long Long ans=0; for (int i=m;i<len;i++) ans+=dp[n&1][i]; printf ("Case #%d:%lld\n", Cs,ans); }}
Hdu5119happy Matt Friends