The Number of set

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

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
 
Source
 
题意:n个集合,每个集合里面有t个数字,每个数字都属于 1-m(m<=14) ,问这些集合合并起来总共有多少可能性??
题解:第一次用状态压缩,,在队友的提示下虽然WA了一次,RE了两次,但是还是挺开心的。
一个集合最多也就有14个数字,我们用 二进制表示 一个集合的所有情况 比如说 某个集合包含 {1,3,11} 那我们的表示为 k = 00010000000101
然后我们每次把当前状态置为a[k] = 1;然后当碰到下一个状态t时,我们就到所有状态(FOR i 1-(1<<14))里面去找a[i]=1
然后a[i|t] = 1 最后遍历求出有多少a[i]为1即可。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define N 14
using namespace std; int a[(<<N)+]; ///14位,最低位存0,2的14次方保存的是 100000000000000可以存15位,所以最大用到 2^14-1 int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
int t,num,k;
memset(a,,sizeof(a));
for(int i=;i<=n;i++){
scanf("%d",&t);
k=;
for(int j=;j<=t;j++){
scanf("%d",&num);
k+=(<<(num-));
}
a[k]=;
for(int j=;j<=(<<N);j++){
if(a[j]){
int next = k|j;
a[next]=;
}
}
}
int ans = ;
for(int i=;i<=(<<N);i++){
if(a[i]) ans++;
}
printf("%d\n",ans);
}
return ;
}

hdu 3006(状态压缩)的更多相关文章

  1. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

  2. hdu 4739(状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4739 思路:状态压缩. #include<iostream> #include<cs ...

  3. HDU 3341 状态压缩DP+AC自动机

    题目大意: 调整基因的顺序,希望使得最后得到的基因包含有最多的匹配串基因,使得所能达到的智商最高 这里很明显要用状态压缩当前AC自动机上点使用了基因的情况所能达到的最优状态 我最开始对于状态的保存是, ...

  4. hdu 2167(状态压缩基础题)

    题意:给你一个矩阵,让你在矩阵中找一些元素使它们加起来和最大,但是当你使用某一个元素时,那么这个元素周围的其它八个元素都不能取! 分析:这是一道比较基础的状态压缩题,也是我做的第三道状态压缩的题,但是 ...

  5. hdu 1565(状态压缩基础题)

    题意:容易理解. 分析:这是我做的状态压缩第二题,一开始超内存了,因为数组开大了,后来超时了,因为能够成立的状态就那么多,所以你应该先把它抽出来!!总的来说还是比较简单的!! 代码实现: #inclu ...

  6. HDU 2553 状态压缩

    N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. hdu 2489(状态压缩+最小生成树)

    Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. hdu 4033 状态压缩枚举

    /* 看别人的的思路 搜索搜不出来我太挫了 状态压缩枚举+好的位置 */ #include<stdio.h> #include<string.h> #define N 20 i ...

  9. HDU 4856 (状态压缩DP+TSP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4856 题目大意:有一个迷宫.迷宫里有些隧道,每个隧道有起点和终点,在隧道里不耗时.出隧道就耗时,你的 ...

随机推荐

  1. Brainf**k(一位数求max)

    题目大意:给你两个一位数,要你求出其中的较大值(使用$Brainf**k$) ($Brainf**k$简介,相当于有一个数组和一个指针,","为把数组当前位赋值为读入的数,&quo ...

  2. [Leetcode] Best time to buy and sell stock 买卖股票的最佳时机

    Say you have an array for which the i th element is the price of a given stock on day i. If you were ...

  3. 【NOIP模拟赛】天神下凡 动态开点线段树

    这些圆一定是在同一水平面上的,由于他们没有相交,因此我们发现他们每个人与外界关系可以分为,1.存在并圈圈 2.存在圈圈并被割,因此我们把所有的圆都加1,把被割的在加1,就可以啦,因此我们开一个线段树, ...

  4. 安卓下拉刷新空间SwipeRefreshLayout的基本使用

    1.先写布局文件 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/refresh" androi ...

  5. CMU Bomblab 答案

    室友拉我做的... http://csapp.cs.cmu.edu/3e/labs.html Border relations with Canada have never been better. ...

  6. Out of memory due to hash maps used in map-side aggregation解决办法

    在运行一个group by的sql时,抛出以下错误信息: Task with the most failures(4): -----Task ID:  task_201411191723_723592 ...

  7. webpack3基础知识

    ## 本地化安装webpack ## 1. npm init //npm初始化生成package.json文件 2. npm install --save-dev webpack //安装webpac ...

  8. 我们用CloudStack做什么

    原文地址:http://www.sdfengxi.com/?p=376 我想很多同学会有类似的疑问,就是我配置好了CloudStack或者OpenStack之类的环境之后能够提供什么服务或者应用呢?下 ...

  9. 单选按钮radio与文字如何对齐?

    布局如下: <input type="radio" value="立即发送" name="a_1">立即发送 <input ...

  10. spring结合Mybatis的框架搭建(一)

    一:前沿 2015年新年上班的第二天,第一天就打了一天的酱油哦,只是下午开始搭建自己毕业设计的框架,搭建的是spring+spring mvc+MyBatis的框架.今天遇到了一个问题,结果弄了我一天 ...