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. hdu_5813_Elegant Construction(xjb搞)

    题目链接:hdu_5813_Elegant Construction 题意: 给你n个点,每个点要可以到达ai个点,可以直接可以间接,不能有环,问是否可行,如果可行就任选一种方式连接,并输出连接的边数 ...

  2. IdentityDbContext类源码

    Microsoft.AspNet.Identity.EntityFramework/IdentityDbContext.cs 源码: 其中涉及到用户信息表.用户角色表的相关操作. using Syst ...

  3. JS预览图像将本地图片显示到浏览器上

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  4. vultr使用snapshots系统镜像备份安装vps

    vultr vps提供免费的snapshots功能,把你的vps做成镜像备份,在必要的时候可以恢复.如果你要配置多台机器,使用Snapshots非常方便好用. vultr添加snapshots很简单, ...

  5. pc app 桌面打包

    进入 http://nwjs.io/  下载 创建web项目,在项目根目录 创建文件package.json并填写 1 2 3 4 5 6 7 {   "name": " ...

  6. winform实现矩形框截图

    使用方法如下: private void button1_Click(object sender, EventArgs e) { s.GerScreenFormRectangle(); } priva ...

  7. erlang四大behaviour之三-gen_event

    来源:http://www.cnblogs.com/puputu/articles/1689623.html 1. 事件处理规则 在OTP中,事件管理器是一个事件可以发送到的命名对象,一个事件可以是一 ...

  8. iOS UIScrollview代理方法

    方法&&属性: // 监控目前滚动的位置(默认CGPointZero) CGPoint contentOffset; - (void)setContentOffset:(CGPoint ...

  9. 为Android系统内置Java应用程序测试Application Frameworks层的硬件服务

    我们在Android系统增加硬件服务的目的是为了让应用层的APP能够通过Java接口来访问硬件服务.那么, APP如何通过Java接口来访问Application Frameworks层提供的硬件服务 ...

  10. applicationContext.xml 配置(扫描)

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...