Happy Matt Friends

Time Limit: 6000/6000 MS (Java/Others)    Memory Limit: 510000/510000 K (Java/Others)

Problem Description
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.

 
分析:由于只有40个数,答案上限为1e6,所以直接暴力枚举转移即可;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
const int maxn=2e6+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,cas;
ll dp[][maxn],ans;
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
ans=;
dp[][]=;
scanf("%d%d",&n,&m);
rep(i,,n)
{
scanf("%d",&k);
for(j=;j<=1e6;j++)dp[i%][j]=dp[(i-)%][j]+dp[(i-)%][j^k];
}
rep(i,m,1e6)ans+=dp[n%][i];
printf("Case #%d: %lld\n",++cas,ans);
}
//system("Pause");
return ;
}

Happy Matt Friends的更多相关文章

  1. [Under the hood]---Matt Pietrek October 1996 MSJ

    Matt Pietrek October 1996 MSJ Matt Pietrek is the author of Windows 95 System Programming Secrets (I ...

  2. hdu 5112 A Curious Matt

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5112 A Curious Matt Description There is a curious ma ...

  3. HDU 5119 Happy Matt Friends

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

  4. HDU 5112 A Curious Matt 水题

    A Curious Matt Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  5. hdoj 5112 A Curious Matt

    A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) ...

  6. 水题:HDU 5119 Happy Matt Friends

    Matt has N friends. They are playing a game together.Each of Matt's friends has a magic number. In t ...

  7. 水题:HDU 5112 A Curious Matt

    Description There is a curious man called Matt. One day, Matt's best friend Ted is wandering on the ...

  8. 听听Matt Rogish说怎么面试程序员

    Google的人力运营高级副总裁Laszlo Bock在一次采访中说Google发现在面试程序员时问智力题完全是浪费时间,Matt Rogish在他的这篇博客How to Interview Prog ...

  9. Happy Matt Friends(dp)

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

随机推荐

  1. 【Python@Thread】锁示例

    当出现竞态条件时候,即在同一个时刻只有一个线程可以进入临界区,需要使用同步. 常见的同步原语有两种:锁/互斥,信号量. 锁是最简单,最低级的机制. 首先看一个不使用锁时候的多线程示例: from at ...

  2. php基础(五)日期

    PHP Date() 函数 date(format,timestamp) 参数 描述 format 必需.规定时间戳的格式. timestamp 可选.规定时间戳.默认是当前时间和日期. 注释:时间戳 ...

  3. 【转】Spring事务超时时间可能存在的错误认识

    1.先看代码 1.1.spring-config.xml <bean id="dataSource" class="org.springframework.jdbc ...

  4. 转 delphi SelText,GetText,SetText用法

    转自:http://blog.163.com/wll_009/blog/static/1173731172009102452632968/ 这几个都跟选区有关的,就是选中一串字符串,选中的会变蓝色Se ...

  5. BestCoder Round #86 A B C

    这次BC终于不像上次一样惨烈 终于A了三题…… 终测ing…… 发一波题解…… A.Price List A题十分无脑 只要把所有数加起来存到sum里 询问的时候大于sum输出1 否则输出0就行了…… ...

  6. gcc-config: Active gcc profile is invalid解决办法

    错误描述 Gentoo软件安装错误,提示: gcc-config: Active gcc profile is invalid 解决方法: 列出可用的profile gcc-config -l gcc ...

  7. Gentoo本地化设置--时区、时钟、字体、中文环境

    时区 你需要选择时区让系统知道你的地理位置,以保持正确的时间.在/usr/share/zoneinfo中查找你的时区.然后在/etc/conf.d/clock中设置时区.请忽略/usr/share/z ...

  8. [译] Block 小测验

    本文来源于 ParseBlog 的其中一篇博文 <Objective-C Blocks Quiz> 如果您觉得我的博客对您有帮助,请通过关注我的新浪微博  MicroCai 支持我,谢谢! ...

  9. 大数据加减(Big data addition and subtraction)

    题目描述 Description 加减法是计算中的基础运算,虽然规则简单,但是位数太多了,也难免会出错.现在的问题是:给定任意位数(不超过1000位)的加减法算式,请给出正确结果.为提高速度,保证给定 ...

  10. mysql数据库的优化技术

    表的设计合理化(遵从3NF)<3范式> 1NF:表的列具有原子性,不可再分解(列的信息不能分解,只要是关系型的数据库就自动满足1NF) 2NF:表中的记录是唯一的,就满足2NF(通常我们设 ...