Happy Matt Friends

Source: Internet
Author: User

Happy Matt Friends

Time limit:6000/6000 MS (java/others) Memory limit:510000/510000 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0


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 single line "Case #x: Y", where x was the case number (starting from 1) and Y indicates the Nu Mber of ways where Matt can win.

Sample Input23 21 2 33 31 2 3

Sample OutputCase #1:4Case #2:2 HintIn the-RST sample, Matt can win by Selecting:friend with number 1 and friend with number 2. The XOR sum is a 3.friend with number 1 and a 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. Problem solving: DP count DP weak to slag AH! The Code of the ape ape giant under the guidance of the great!
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <climits>7#include <vector>8#include <queue>9#include <cstdlib>Ten#include <string> One#include <Set> A#include <map> -#include <stack> - #defineLL Long Long the #defineINF 0x3f3f3f3f - #definePII pair<int,int> - using namespacestd; - Const intMAXN =1<< +; + intdp[2][maxn],d[ A],n,m; - intMain () { +     intt,cs=1; Ascanf"%d",&T); at      while(t--) { -scanf"%d%d",&n,&m); -Memset (DP,0,sizeof(DP)); -          for(inti =0; I < n; ++i) -scanf"%d", d+i); -LL ans =0; indp[0][0] =1; -         intCur =0; to          for(inti =0; I < n; ++i) { +memset (dp[cur^1],0,sizeof(dp[cur^1])); -              for(intj =0; J < Maxn; ++j) { the                 intTMP = j^D[i]; *dp[cur^1][TMP] + =Dp[cur][j]; $dp[cur^1][J] + =Dp[cur][j];Panax Notoginseng             } -Cur ^=1; the         } +          for(inti = m; i < MAXN; ++i) A             if(Dp[cur][i]) ans + =Dp[cur][i]; theprintf"Case #%d:%i64d\n", cs++, ans); +     } -     return 0; $}
View Code

Happy Matt Friends

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.