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. 从CSDN转战于此

    平时喜欢写博客,开始是再CSDN,但CSDN博客功能实在不是很好.听说博客园的博客功能很不错,今天就来到此地.实际上很早就注册了博客园,但博客今天才申请的. 博客园,来了!

  2. HW--字符串加解密

    package t0817; import java.util.Scanner; public class StringEncrypt { public static void main(String ...

  3. eclipse中启动Genymotion模拟器的错误

    错误程序: Output file: C:\Users\wishwzp\.genymotion-eclipse.logLoading Genymotion libraryGenymotion dire ...

  4. C# 预处理指令

    导读 1.什么是预处理 2.预处理的好处 3.C#中的常见预处理指令 4.总结 什么是预处理         在计算机科学中,预处理通常是指利用某一程序(通常是预处理器)对某一格式的源码(如.cs C ...

  5. 数据库E-R模型,数据字典

    概述:实体-联系模型(简称E-R模型) 模型结构: E-R模型的构成成分是实体集.属性和联系集,其表示方法如下: (1) 实体集用矩形框表示,矩形框内写上实体名. (2) 实体的属性用椭圆框表示,框内 ...

  6. [MAXscript Tool]TimeSlider v1.3

    一个简单的小工具,方便在MAX里面快速的修改帧速率,像maya一样.具体看视频演示.

  7. 11_Jaxws常用注解

    [不使用注解] 默认namespace是服务类包名的倒序 默认portType是服务类的类名 ............... 注解的所起的作用: Jaxws提供的注解可以对WebService的接口规 ...

  8. 安装Cygwin

    如果你现在正在学习C语言,而你又不希望使用微软提供的任何C语言的任何编译器,那么你应该考虑一下GCC.GCC是运行于类UNIX系统下的编译器工具集,这又引出了另一个让人头疼的问题,你没有一台现成的装有 ...

  9. RX学习笔记:JavaScript数组操作

    RX学习笔记:JavaScript数组操作 2016-07-03 增删元素 unshift() 在数组开关添加元素 array.unshift("value"); array.un ...

  10. 【转】C#.net拖拽实现获得文件路径

    C#.net拖拽实现获得文件路径 作者Attilax ,  EMAIL:1466519819@qq.com 思路: 通过DragEnter事件获得被拖入窗口的“信息”(可以是若干文件,一些文字等等), ...