Matt has N friends. They are playing a game together.

Each of Matt’s friends has a magic number. In the game, Matt selects some (could be 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 two integers N, M (1 ≤ N ≤ 40, 0 ≤ M ≤ 106).

In the second line, there are 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 is the case number (starting from 1) and y indicates the number of ways where Matt can win.

 

Sample Input

2
3 2
1 2 3
3 3
1 2 3

Sample Output

Case #1: 4
Case #2: 2

Hint

In the first 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 2. friend with number 2. The xor sum is 2. friend with number 3. The xor sum is 3. Hence, the answer is 4.
  水DP。
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int Max=;
int dp[][Max],n,M;
int main(){
int T,cas=;
long long ans,tot,x;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&M);
memset(dp,,sizeof(dp));
dp[][]=;int now,pre;
for(int i=;i<=n;i++){
scanf("%lld",&x);now=i%,pre=now^;
memset(dp[now],,sizeof(dp[now]));
for(int j=;j<Max;j++){
if((j^x)<Max)dp[now][j]+=dp[pre][j^x];
dp[now][j]+=dp[pre][j];
}
}
ans=;
for(int i=;i<M;i++)ans+=dp[now][i];
tot=;x=;
while(n){
if(n&)tot=tot*x;
n>>=;x=x*x;
}
printf("Case #%d: %lld\n",++cas,tot-ans);
}
return ;
}

水题:HDU 5119 Happy Matt Friends的更多相关文章

  1. HDU 5119 Happy Matt Friends (背包DP + 滚动数组)

    题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...

  2. HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)

    虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[ ...

  3. HDU 5119 Happy Matt Friends(递推)

    http://acm.hdu.edu.cn/showproblem.php?pid=5119 题意:给出n个数和一个上限m,求从这n个数里取任意个数做异或运算,最后的结果不小于m有多少种取法. 思路: ...

  4. HDU 5119 Happy Matt Friends (14北京区域赛 类背包dp)

    Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 510000/510000 K (Java/Oth ...

  5. HDU 5119 Happy Matt Friends

    Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others ...

  6. 水题~~~~HDU 4788

    Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gi ...

  7. 又是一道水题 hdu背包

    Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...

  8. HDU 5119 Happy Matt Friends(dp+位运算)

    题意:给定n个数,从中分别取出0个,1个,2个...n个,并把他们异或起来,求大于m个总的取法. 思路:dp,背包思想,考虑第i个数,取或者不取,dp[i][j]表示在第i个数时,异或值为j的所有取法 ...

  9. HDU - 5119 Happy Matt Friends(dp)

    题目链接 题意:n个数,你可以从中选一些数,也可以不选,选出来的元素的异或和大于m时,则称满足情况.问满足情况的方案数为多少. 分析:本来以为是用什么特殊的数据结构来操作,没想到是dp,还好队友很强. ...

随机推荐

  1. iTerm 使用expect实现自动远程登录,登录跳板机

    #!/usr/bin/expect set timeout 10 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] exp ...

  2. 2014年12月20日00:33:14-遮罩+进度条-extjs form.isvalid

    1.Extjs : 遮罩+进度条 2.Extjs: extjs form.isvalid http://stackoverflow.com/questions/19354433/extjs-form- ...

  3. Poj 2115 C Looooops(exgcd变式)

    C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22704 Accepted: 6251 Descripti ...

  4. 编程语言的发展趋势by Anders Hejlsberg

    这是Anders Hejlsberg在比利时TechDays 2010所做的开场演讲. 编程语言的发展非常缓慢,期间也当然出现了一些东西,例如面向对象等等,你可能会想,那么我么这么多年的努力都到哪里去 ...

  5. Maven多层嵌套

    <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...

  6. HTML教程:link标记

    开发php语言的网站,<head>里link标签这样:<link href="xmlrpc.php?rsd=1" title="rsd" ty ...

  7. 深度学习算法实践15---堆叠去噪自动编码机(SdA)原理及实现

    我们讨论了去噪自动编码机(dA),并讨论了Theano框架实现的细节.在本节中,我们将讨论去噪自动编码机(dA)的主要应用,即组成堆叠自动编码机(SdA),我们将以MNIST手写字母识别为例,用堆叠自 ...

  8. MVC + JQUERY + AJAX

  9. 将yyyyMMdd HH:mm:ss格式的时间转换成时间类型

    DateTime.ParseExact(gmt_withdrawal, "yyyyMMddHHmmss", System.Globalization.CultureInfo.Cur ...

  10. jQuery实现iframe的自适应高度

    假设我们在当前页面要嵌套一个iframe 1 <iframe id="myframe" src="test.html" height="240& ...