http://acm.hdu.edu.cn/showproblem.php?pid=5119
Happy Matt FriendsTime limit:6000/6000 MS (java/others) Memory limit:510000/510000 K (java/others)
Total submission (s): 341 Accepted Submission (s): 130
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
2 3 2 1 2 3 3 3 1 2 3
Sample Output
Case #1:4 case #2:2 Hint
SOURCE2014ACM/ICPC Asia Beijing Station-Replay (thanks to the North Division and handing in)
Problem-Solving ideas: DP
1 #include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5
6ConstintMAX = (1<< -);
7
8LongLongdp[ A][max];
9intN, W, a[ A];
Ten
OneintMain () {
AintT, I, J;
-intCase =1;
-scanf"%d", &t);
the while(t--) {
-scanf"%d%d", &n, &w);
- for(i =0; I < n; i++) {
-scanf"%d", &a[i]);
+}
-Memset (DP,0,sizeof(DP));
+dp[0][0] =1;
ALongLongAns =0;
atif(W = =0){
-ans++;
-}
- for(i =0; I < n; i++) {
- for(j =0; J < MAX; J + +) {
-if(Dp[i][j] = =0){
inContinue;
-}
toDp[i +1][J] + = dp[i][j];
+intNJ = J^a[i];
-Dp[i +1][NJ] + = dp[i][j];
theif(NJ >= W) {
*Ans + = dp[i][j];
$}
Panax Notoginseng}
-}
theprintf"Case #%d:%i64d\n", case++, ans);
+}
Areturn0;
the}
Hdu-5119-happy Matt Friends