Test instructions no longer say, is a two-dimensional DP, maintain the maximum value is how much.
Happy Matt FriendsTime limit:6000/6000 MS (java/others) Memory limit:510000/510000 K (java/others)
Total submission (s): 608 Accepted Submission (s): 229
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)
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <ctime> #include <map> #include <set> #define EPS 1e-9///#define M 1000100///#define ll __int64#define ll Long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero (x) ((FA BS (x) <eps)? 0:x) #define MoD 1000000007using namespace std;const int maxn = 1<<20;inline int read () {char ch; BOOL flag = FALSE; int a = 0; while (!) ( ((ch = getchar ()) >= ' 0 ') && (ch <= ' 9 ')) | | (ch = = '-'))); if (ch! = '-') {a *= 10; A + = ch-' 0 '; } else {flag = true; The while ((ch = getchar ()) >= ' 0 ') && (ch <= ' 9 ')) {a *= 10; A + = ch-' 0 '; } if (flag) {a = A; } return A; void write (int a) {IF (A < 0) {Putchar ('-'); A =-A; } if (a >=) {write (A/10); } putchar (a% 10 + ' 0 ');} LL dp[45][maxn+100];int Num[45];int Main () {int T; CIN >>T; int case = 1; while (t--) {int n, m; n = read (); m = read (); for (int i = 1; I <= n; i++) Num[i] = read (); memset (DP, 0, sizeof (DP)); Dp[0][0] = 1LL; for (int i = 1, i <= N; i++) {for (int j = 0; J <= Maxn-5; j + +) {Dp[i][j ] = max (Dp[i][j], dp[i-1][j]+dp[i-1][j^num[i]); }} LL sum = 0; for (int i = m; I <= maxn-5; i++) sum + = Dp[n][i]; printf ("Case #%d:", case++); cout<<sum<<endl; }}
HDU 5119 Happy Matt Friends (simple two-dimensional DP)