Happy Matt Friends
Time limit:6000/6000 MS (java/others) Memory limit:510000/510000 K (java/others)
Total submission (s): Accepted submission (s): 56
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)
recommendliuyiding | We have carefully selected several similar problems for you:5126 5125 5122 5121 5118
The puzzle is Gaussian elimination (really not very good)
With a backpack, and then add a rolling array, initially tangled in the first I the number of different or largest, and then how all can not, and then simply all to change the upper limit to 1 << 20, and then over the
#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring># Include <iostream> #include <algorithm>using namespace Std;__int64 dp[2][1 << 22];int num[44];int Main () {int T, n, m, icase = 1;__int64 ans;scanf ("%d", &t), while (t--) {memset (DP, 0, sizeof (DP)), scanf ("%d%d", &n, &am P;M); for (int i = 1; I <= n; ++i) {scanf ("%d", &num[i]);} Dp[0][0] = 1;for (int i = 1; I <= n; ++i) {for (int j = 0; J <= (1 <<); ++j) {dp[i% 2][j] = dp[1-(i% 2)] [ J] + dp[1-(i% 2)][j ^ num[i];}} ans = 0;for (int i = m; I <= (1 <<); ++i) {ans + dp[n% 2][i];} printf ("Case #%d:%i64d\n", icase++, ans);} return 0;}
Hdu5119--happy Matt Friends