Happy Matt Friends
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.

InputThe 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 ≤ 10 6).

In the second line, there are N integers ki (0 ≤ k i ≤ 10 6), indicating the i-th friend’s magic number.OutputFor 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.

14年北京站题~题目意思:给出t组数据 n个数 求XOR出大于m的数的个数,每个数都有两种状态,取与不取。其实就是一个01背包。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
const int MOD=1e9+7;
ll a[maxn];
int dp[45][maxn],n,m;
ll slove()
{dp[1][0]=dp[1][a[1]]=1;for(int i=2; i<=n; i++){for(ll j=0; j<maxn; j++){dp[i][j]+=dp[i-1][j];dp[i][j^a[i]]+=dp[i-1][j];}}ll ans=0;for(ll i=m; i<maxn; i++){ans+=dp[n][i];}return ans;
}
int main()
{int t,k=0;scanf("%d",&t);while(t--){memset(dp,0,sizeof(dp));scanf("%d %d",&n,&m);for(int i=1; i<=n; i++)scanf("%lld",&a[i]);ll ans=slove();printf("Case #%d: %lld\n",++k,ans);}return 0;
}

PS:摸鱼怪的博客分享,欢迎感谢各路大牛的指点~

转载于:https://www.cnblogs.com/MengX/p/9074603.html

HDU-5119 Happy Matt Friends相关推荐

  1. HDU 5119 Happy Matt Friends(递推)

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

  2. HDU 5119 Happy Matt Friends ——(背包DP)

    题意:有最多40个数字,取任意个数字他们的异或和>=k则是可行的方案,问有多少种可行的方案. 分析:dp[now][j]表示当前这个值的种类数,那么转移方程为dp[now][j] = dp[pr ...

  3. HDU 5119 Happy Matt Friends(DP || 高斯消元)

    题目链接 题意 : 给你n个数,让你从中挑K个数(K<=n)使得这k个数异或的和小于m,问你有多少种异或方式满足这个条件. 思路 : 正解据说是高斯消元.这里用DP做的,类似于背包,枚举的是异或 ...

  4. hdu 5119 (类似于划分数的状态定义) (DP中的计数问题)

    题目描述:求n个数中异或值大于m的方案数有多少个? 设状态f[i][j]代表前i个数异或值为j的方案数有f[i][j]种,那么对于j来说要么选第i个数与前面的i-1个数中的某些数构成j,f[i-1][ ...

  5. 2014_beijing_onsite

    5112 A Curious Matt 签到,排序题目 5113 Black And White 5*5的方格,dfs+剪枝 5114 Collision 线性方程求解 扩展欧几里得 5115 Dir ...

  6. HDU 5112 A Curious Matt 水题

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

  7. hdu 5112 A Curious Matt

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

  8. HDU 5115 Dire Wolf 区间dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...

  9. Happy Matt Friends(HDU5119 + dp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5119 题目: 题意: 求选择任意个数,使其异或和大于等于m的方案数. 思路: 每个数有选和不选两种方 ...

  10. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

最新文章

  1. app前后台交互php_PHP丨前端网页是怎么跟后台进行数据交互的(实战)
  2. 史上最大“云办公”实验开始,你参加了吗?
  3. LeetCode Rectangle Area
  4. 源码安装python
  5. Dynamics AX 2012 R2 外部程序运行在没有AD的环境(如PDA) 调用AX服务
  6. 用异或的性质实现简单加密解密
  7. 神技能!在上司靠近座位时,用人脸识别技术及时屏幕切换
  8. 提高网站性能之 —— 减少图片HTTP 请求的方案
  9. python: ubuntu下把py2.7改成py3
  10. 快速突破面试算法之分治算法篇
  11. 如何制作优秀的PPT
  12. 如何理解前后端分离HTML5,Web前后端分离开发思路
  13. (转)Intel Atom处理器详细指标及市场前景
  14. React lazyLoad懒加载
  15. 三国志战略版:SP吕蒙携手都督重出江湖
  16. 深度学习细粒度图像研究汇总
  17. win10桌面快捷方式图标变白
  18. 百分点大数据技术团队:可插拔OSS架构设计和实战经验
  19. Android TextWatcher 避免死循环
  20. 华为防火墙(NAT)

热门文章

  1. C#.net调用Excel出现问题
  2. ⑨④-如果不发展就可能面临生存窘境
  3. 获取python工程下面的所需的所有开源依赖包
  4. Exception in thread main org.apache.thrift.transport.TTransportException: Could not create ServerS
  5. 操作系统 哈工大 李治军
  6. SVM(一) 问题的提出
  7. java中volatile关键字---学习笔记
  8. [学习笔记]后缀自动机
  9. amazeui学习笔记一(开始使用4)--Web App 相关
  10. CORS解决WebApi跨域问题(转)