Happy Matt Friends (DP)

Source: Internet
Author: User

Happy Matt Friends

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


Problem Description

Matt 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.

Input

The 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.

Output

For 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 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 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.

Source

2014ACM/ICPC Asia Beijing Station-Replay (thanks to the North Division and handing in)

Test instructions: The first line T, then the 2 integer n,m, and then give n numbers, ask any combination of these numbers, or the number of combinations greater than or equal to M

T: Violence DP can dp[i][j] to the number of the first I can be composed of the number of XOR and equal to J

DP[I][J] = DP [I-1][J] + dp[i-1][j^num[i]

Can scroll, can not scroll

1#include <iostream>2#include <stdio.h>3#include <string.h>4 using namespacestd;5 #defineLL Long Long6 #defineMX 10000057 8 intScan () {//input Plug -in9     intres =0, flag =0;Ten     Charch; One     if(ch = getchar ()) = ='-') flag =1; A     Else if(Ch >='0'&& CH <='9') res = CH-'0'; -      while(ch = getchar ()) >='0'&& CH <='9') -res = res *Ten+ (CH-'0'); the     returnFlag? -Res:res; - } -  - voidOut (intA) {//Output Plug +     if(A <0) {Putchar ('-'); A =-A;} -     if(A >=Ten) Out (A/Ten); +Putchar (A%Ten+'0'); A } at  - intn,m; - intdp[2][1<< +];//I number of different OR and J number - intNUM[MX]; -  - intMain () in { -     intT; toCin>>T; +      for(intCnt=1; cnt<=t;cnt++) -     { theN=scan (), m=Scan (); *          for(intI=1; i<=n;i++) $scanf"%d",&num[i]);Panax NotoginsengMemset (DP,0,sizeof(DP)); -dp[0][0]=1; the          for(intI=1; i<=n;i++) +         { A              for(intj=0; j<mx;j++) the             { +dp[i&1][j]=dp[(I-1) &1][j]+dp[(I-1) &1][j^Num[i]]; -             } $         } $LL ans =0; -          for(inti=m;i<mx;i++) -Ans + = dp[n&1][i]; theprintf"Case #%d:%i64d\n", Cnt,ans); -     }Wuyi     return 0; the}
View Code

Happy Matt Friends (DP)

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.