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. iOS开发——百度地图SDK集成

    (正在形成文档,待更新……)

  2. excel导入 导出 兼容各个版本服务器不装EXCEL也可以

    给出 demo源码: http://pan.baidu.com/s/1hqGMudY 提取码:pw4n首先要引用 NPOI.dll (可在网上下载!) //导入 public void OnSubmi ...

  3. 05_天气查询_JAX-WS方式_客户端

    [客户端特点] 支持面向对象开发. 客户端功能调用webService,首先得知道WebService的地址. 一般情况下,只要知道了wsdl的地址,就可以知道WebService的地址. 我们上一篇 ...

  4. 【实习记】2014-09-26恢复linux下误删的ntfs盘中的文件

        情景,ubuntu下把NTFS格式的盘中的“实习记”文件夹彻底删除了,追毁莫及,粗心觉不是一件好的事情. linux下回复ntfs盘下的文件不能用ext3grep,而使用debugfs命令实在 ...

  5. jQuery EasyUI 提示框(Messager)用法

    jQuery EasyUI 提示框(Messager)不仅强大,而且也不用任何的HTML代码,只需要按照<jQuery EasyUI框架使用文档>包含必要文件后,在$(function() ...

  6. php 常用五种模式

    /* 设计模式之单例模式 $_instance 必须声明为静态的私有变量 构造函数必须声明为私有,防止外部程序 new 类从而失去单例模式的意义 getInstance() 方法必须设置为公有的,必须 ...

  7. html5异步上传图片显示上传文件进度条

    <html> <head> </head> <body> <p> emo_album_id:<input type="tex ...

  8. 京东电话面试——PHP开发

    1.学过<数据结构>吗?你学过的计算机相关课程有哪些? 2.web操作中,当你输入一个url到看到页面,描述一下这中间发生了什么? 3.TCP/IP的请求方式都有哪些? 4.POST和GE ...

  9. 刷新dns

    1.window:ipconfig /flushdns 2.linux sudo rcnscd restart

  10. Android 自定义View实现单击和双击事件

    自定义View, 1. 自定义一个Runnable线程TouchEventCountThread ,  用来统计500ms内的点击次数 2. 在MyView中的 onTouchEvent 中调用 上面 ...