水题:HDU 5119 Happy Matt Friends
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
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
Sample Input
2
3 2
1 2 3
3 3
1 2 3
Sample Output
Case #1: 4
Case #2: 2
Hint
#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的更多相关文章
- HDU 5119 Happy Matt Friends (背包DP + 滚动数组)
题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...
- HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)
虽然是一道还是算简单的DP,甚至不用滚动数组也能AC,数据量不算很大. 对于N个数,每个数只存在两个状态,取 和 不取. 容易得出状态转移方程: dp[i][j] = dp[i - 1][j ^ a[ ...
- HDU 5119 Happy Matt Friends(递推)
http://acm.hdu.edu.cn/showproblem.php?pid=5119 题意:给出n个数和一个上限m,求从这n个数里取任意个数做异或运算,最后的结果不小于m有多少种取法. 思路: ...
- HDU 5119 Happy Matt Friends (14北京区域赛 类背包dp)
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Oth ...
- HDU 5119 Happy Matt Friends
Happy Matt Friends Time Limit: 6000/6000 MS (Java/Others) Memory Limit: 510000/510000 K (Java/Others ...
- 水题~~~~HDU 4788
Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gi ...
- 又是一道水题 hdu背包
Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负) ...
- HDU 5119 Happy Matt Friends(dp+位运算)
题意:给定n个数,从中分别取出0个,1个,2个...n个,并把他们异或起来,求大于m个总的取法. 思路:dp,背包思想,考虑第i个数,取或者不取,dp[i][j]表示在第i个数时,异或值为j的所有取法 ...
- HDU - 5119 Happy Matt Friends(dp)
题目链接 题意:n个数,你可以从中选一些数,也可以不选,选出来的元素的异或和大于m时,则称满足情况.问满足情况的方案数为多少. 分析:本来以为是用什么特殊的数据结构来操作,没想到是dp,还好队友很强. ...
随机推荐
- use mkisofs 重新打包beini,tinycore linux
mkisofs -r -J -V Beini-Custom -v --boot-info-table --boot-load-size 4 -b boot/isolinux/isolinux.bin ...
- 15_AOP入门准备_静态代理模式
[工程截图] [PersonDao.java] package com.HigginCui.daoProxy; public interface PersonDao { public void sav ...
- ERROR 1045 (28000): Access denied for user 'root'@'localhost'
# /etc/init.d/mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysq ...
- bzoj2653:middle
思路:首先容易想到二分答案,但如何去check呢,对于一段区间[l,r],把所有小于答案的都赋值为-1,大于等于它的都赋值为1,然后求左端点在[a,b],右端点在[c,d]的最大子串和即可(也就是区间 ...
- 九度OJ 1361 翻转单词顺序
题目地址:http://ac.jobdu.com/problem.php?pid=1361 题目描述: JOBDU最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上.同事Ca ...
- 九度OJ 1087 约数的个数
题目地址:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...
- MVC的发展
ASP.NET下的MVC从原始的1.0走到2.0,再到3.0,现在走到4.0,也许明年5.0就问世了,先不管那些,那说说这些MVC在ASP.NET是如何变化发展的.对于.net编程人员来说可能会很熟悉 ...
- 【转】Vim命令合集以及乱码问题解决
乱码问题 """""""""""""""" ...
- linux文件属性权限相关
一个linux目录或者文件,都会有一个所属主和所属组. 所属主,即文件的拥有者,而所属组,即该文件所属主所在的一个组. linux文件属性 包括文件类型 - d l b c s 依次表示 普通文件 ...
- centos VM 识别U盘
在VM设置选项中,选择 USB Controller 选项,设置相关参数即可