N*m violence dp ....
Happy Matt FriendsTime limit:6000/6000 MS (java/others) Memory limit:510000/510000 K (java/others)
Total submission (s): Accepted submission (s): 34
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 <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef long long int LL; LL dp[2][1<<20+1];int a[100];int n,m;int main () {int t_t,cas=1; scanf ("%d", &t_t); while (t_t--) {scanf ("%d%d", &n,&m); memset (A,0,sizeof (a)); Memset (Dp,0,sizeof (DP)); for (int i=1;i<=n;i++) scanf ("%d", a+i); int now=1,pre=0; DP[0][0]=1LL; for (int i=1;i<=n;i++) {memset (dp[now],0,sizeof (Dp[now])); for (int j=0;j<= (1<<20); j + +) {if (dp[pre][j]) {int x= J^a[i]; DP[NOW][X]+=DP[PRE][J]; DP[NOW][J]+=DP[PRE][J]; }} swap (Now,pre); } LL ans=0; for (int i=m;i<= (1<<20); i++) ans+=dp[pre][i]; printf ("Case #%d:%i64d\n", Cas++,ans); } return 0;}
Hdoj 5119 Happy Matt Friends DP