描述

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

输入

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.

输出

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.

样例输入

2
3 2
1 2 3
3 3
1 2 3

样例输出

Case #1: 4
Case #2: 2

提示

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.

题意

N个数选择任意个数求异或和大于M的方案数。

题解

计数DP。

dp[i][j]代表第i个物品异或和为j的方案数。

显然dp[i][j]=dp[i-1][j]+dp[i-1][j^a[i]](不装i或者装i)。

由于j高达1e6,所以需要滚动一维i。

代码

 #include<bits/stdc++.h>
using namespace std; #define LL long long
LL dp[][<<];
int main()
{
ios::sync_with_stdio(false),cin.tie(),cout.tie();
int t,n,m,ca=,a[];
cin>>t;
while(t--)
{
cin>>n>>m;
int mx=;
for(int i=;i<=n;i++)cin>>a[i],mx=max(mx,a[i]);
int sta=;
while(sta<=mx)sta<<=;
for(int i=;i<sta;i++)dp[][i]=dp[][i]=;
dp[][]=;
int cur=;
for(int i=;i<=n;i++,cur^=)
{
for(int j=;j<sta;j++)
dp[cur][j]=dp[cur^][j]+dp[cur^][j^a[i]];
for(int j=;j<sta;j++)
dp[cur^][j]=;
}
LL sum=;
for(int i=m;i<sta;i++)sum+=dp[cur^][i];
cout<<"Case #"<<ca++<<": "<<sum<<endl;
}
return ;
}

TZOJ 5962 Happy Matt Friends(计数DP)的更多相关文章

  1. HDU5800 To My Girlfriend 背包计数dp

    分析:首先定义状态dp[i][j][s1][s2]代表前i个物品中,选若干个物品,总价值为j 其中s1个物品时必选,s2物品必不选的方案数 那么转移的时候可以考虑,第i个物品是可选可可不选的 dp[i ...

  2. CodeForces 176B Word Cut (计数DP)

    Word Cut Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  3. [DP之计数DP]

    其实说实在 我在写这篇博客的时候 才刚刚草了一道这样类型的题 之前几乎没有接触过 接触过也是平时比赛的 没有系统的做过 可以说0基础 我所理解的计数dp就是想办法去达到它要的目的 而且一定要非常劲非常 ...

  4. HDU4815/计数DP

    题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=4815] 简单说一下题意: 有n道题,每到题答对得分为a[ i ],假如A不输给B的最小概率是P,那么A ...

  5. HDU 6377 度度熊看球赛 (计数DP)

    度度熊看球赛 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  6. 计数dp

    计数dp 计数类的$dp$没做过几个,所以之前都放到"思维"标签下了,后来发现原来这属于一类问题啊...搬过来了. 管道取珠:https://www.lydsy.com/Judge ...

  7. [SDOI2010]地精部落[计数dp]

    题意 求有多少长度为 \(n\) 的排列满足 \(a_1< a_2> a_3 < a_4 \cdots\) 或者 $a_1> a_2 < a_3 > a_4\cdo ...

  8. 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas

    [题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...

  9. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

随机推荐

  1. DNS配置-BIND安装配置全过程

    下载地址:ftp://ftp.isc.org/isc/ 下载bind,我下载的是bind-9.11.13.tar.gz 我下载的文件放在/root目录下进入目录解压缩 [root@localhost ...

  2. 2019-6-23-天河2-程序-version-GLIBCXX_3.4.21-not-found-解决方法

    title author date CreateTime categories 天河2 程序 version GLIBCXX_3.4.21 not found 解决方法 lindexi 2019-06 ...

  3. T3118 01完美矩阵【计数,前缀和,差分,好题】

    Online Judge:未知 Label:好题,计数,前缀和 题目描述 一个01矩形被称为是完美01矩形,如果满足下面3个条件: (1)它的四条边上都是1 (2)内部(除了4条边)的0和1的个数之差 ...

  4. [JZOJ4769]【GDOI2017模拟9.9】graph

    题目 描述 题目大意很明确了,所以不说-- 思考历程 一看见这题,咦,这就是传说中的动态图吗? 普通的动态图是维护连通性,这题是维护它是否是二分图,换言之就是维护它是否有奇环. 好像很复杂的样子. 想 ...

  5. 数据结构学习笔记_树(二叉搜索树,B-树,B+树,B*树)

    一.查找二叉树(二叉搜索树BST) 1.查找二叉树的性质 1).所有非叶子结点至多拥有两个儿子(Left和Right): 2).所有结点存储一个关键字: 3).非叶子结点的左指针指向小于其关键字的子树 ...

  6. 0818NOIP模拟测试赛后总结

    又挂了…… 120 rank19. 第一次两个机房考不同的题目.一开始并不知道应该做哪套题目. 不明真相的吃瓜群众决定先点开B套.通读三道题,只是觉得T2好水.似乎是红题难度吧……(后来证明是我读错题 ...

  7. P++ 1.0.5

    #include<bits/stdc++.h> #define begin { #define end } #define while while( #define if if( #def ...

  8. js图片预加载实现!

    var myImage = (function(){ var imgNode = document.createElement( 'img' ); document.body.appendChild( ...

  9. 用区块链技术做一个 不可被修改的 恋爱记录 app 我叫<<誓言>>

    区块链技术 具有不可篡改,去中心化,共识机制等优秀的特性, 都用来做 代币钱包什么的.我觉得完全是浪费. 我的想法是用哪个区块做一个dapp 1 里面写着每个人的恋爱记录,爱情宣言. 2 一个人一生 ...

  10. Apollo Lake设计缺陷,避免使用它们

    很多经验告诉我们,在不大幅加电压超频的情况下,CPU很少会用坏.多数情况下电脑退役都是主板或其他部件故障,或是性能严重落后而不得不淘汰.但是如果CPU在制造阶段就存有缺陷的话,情况就不是这样了. 英特 ...