The Number of set

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1002    Accepted Submission(s): 626

Problem Description
Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use these sets to combinate the new set,how many different new set you can get.The given sets can not be broken.
 
Input
There are several cases.For each case,the first line contains two positive integer n and m(1<=n<=100,1<=m<=14).Then the following n lines describe the n sets.These lines each contains k+1 positive integer,the first which is k,then k integers are given. The input is end by EOF.
 
Output
For each case,the output contain only one integer,the number of the different sets you get.
 
Sample Input
4 4
1 1
1 2
1 3
1 4
2 4
3 1 2 3
4 1 2 3 4
 
Sample Output
15
2
 

分析:由于m较小,所以可以用相应的位记录出现的数,这样每一个集合就可以用一个数表示了,能够成的集合也就是这些书进行|运算后得到的所有不同数个数了

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=1<<15;
bool mark[MAX];
int s[MAX]; int main(){
int n,m,k,a;
while(cin>>n>>m){
m=1<<(m+1);
memset(s,0,sizeof s);
memset(mark,false,sizeof mark);
mark[0]=true;
for(int i=0;i<n;++i){
cin>>k;
while(k--){
cin>>a;
s[i]=s[i]|(1<<a);
}
for(int j=0;j<m;++j){
if(mark[j])mark[s[i]|j]=true;
}
}
int num=0;
for(int j=1;j<m;++j)num+=mark[j];
cout<<num<<endl;
}
return 0;
}

hdu3006之位压缩的更多相关文章

  1. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  2. NowCoder猜想(素数筛法+位压缩)

    在期末被各科的大作业碾压快要窒息之际,百忙之中抽空上牛客网逛了逛,无意中发现一道好题,NowCoder猜想,题意很明显,就是个简单的素数筛法,但竟然超内存了,我晕(+﹏+)~  明明有 3 万多 k ...

  3. scala位压缩与行情转换二进制

    import org.jboss.netty.buffer.{ChannelBuffers, ChannelBuffer} import java.nio.charset.Charset import ...

  4. hdu 1429 胜利大逃亡(续)(bfs+位压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. POJ 2443 Set Operation (按位压缩)

    Description You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set ...

  6. hdu3006(状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3006 题意:给定一些集合,求这些集合所能组合的集合个数. 分析:这题就是用一个二进制数保存一个集合的元 ...

  7. POJ 2965 The Pilots Brothers' refrigerator (枚举+BFS+位压缩运算)

    http://poj.org/problem?id=2965 题意: 一个4*4的矩形,有'+'和'-'两种符号,每次可以转换一个坐标的符号,同时该列和该行上的其他符号也要随之改变.最少需要几次才能全 ...

  8. poj1753 Flip Game(BFS+位压缩)

    题目链接 http://poj.org/problem?id=1753 题意 一个棋盘上有16个格子,按4×4排列,每个格子有两面,两面的颜色分别为黑色和白色,游戏的每一轮选择一个格子翻动,翻动该格子 ...

  9. SPOJ BALNUM ★(位压缩状态+数位DP)

    题意 求区间[A,B]上的平衡数个数.平衡数是这样的数:在数的各个位上,奇数数字出现偶数次,偶数数字出现奇数次. 思路 很明显我们需要记录每一位出现的次数.分别记录是不明智的,而我们又只需要记录奇数次 ...

随机推荐

  1. 前台页面Josn 数组在后台.cs代码中的解析

    后台代码: //解析jObject字符串 json_wang 2015/01/27 //var passengerListStr = BookingTicket_PassengerList_Hidde ...

  2. [jquery]高级篇--js绑定事件

    参考:  http://www.cnblogs.com/leejersey/p/3545372.html jQuery on()方法是官方推荐的绑定事件的一个方法.$(selector).on(eve ...

  3. Array.splice返回值是数组

    import flash.display.MovieClip; import flash.display.DisplayObject; var m:MovieClip = new MovieClip( ...

  4. Action Filters for ASP.NET MVC

    本文主要介绍ASP.NET MVC中的Action Filters,并通过举例来呈现其实际应用. Action Filters 可以作为一个应用,作用到controller action (或整个co ...

  5. EL表达式 入门

    为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法. JSP EL语言定义 E L(Expression L ...

  6. 用函数的地址调用函数 C++ MFC

    先说一段废话,幸亏我汇编基础(基础 基础 基础)扎实,否则这个问题真的恶心到我了正题  因为有特殊需求, 需要写一个类似于接口的功能,但是因为用到的次数不多再加上C++写接口各种麻烦所以想通过函数的地 ...

  7. Project Israfil -- 支持多个音乐平台的开源音乐服务

    Israfil     |关于|当前进度|开发日志|下载软件|编译|参与项目|编译状态|版权|协议| LER0ever Project Israfil Provide Unified Music Se ...

  8. WinForm应用程序退出的方法

    this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出. Application.Exit(); 强制所有消息中止,退出所有的 ...

  9. centos6.3安装openvpn客户端

    centos6.3安装openvpn客户端 Centos 默认是没有提供Openvpn的,而且在yum 的源里面也没有openvpn ,如果想使用yum安装的话要首先安装EPEL这个东西.www.2c ...

  10. one makefile file

    #gcc test.cpp -L. -Wl,-Bdynamic -ltestlib -Wl,-Bstatic -ltestlib -Wl,-Bdynamic #make clean; make ini ...