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. POI实现excel的数据验证

    目录 前言 难点1:合并单元格 代码实现策略: step 1: 合并单元格 step 2: 给单元格赋值 难点2:数据验证-下拉框 代码实现策略: step 1:设置需要进行数据验证的单元格范围和可供 ...

  2. HDU 2139 Calculate the formula

    http://acm.hdu.edu.cn/showproblem.php?pid=2139 Problem Description You just need to calculate the su ...

  3. vue里的this

    vue中methods对象里的函数, this指向的都是当前实例或者组件.

  4. vue中表单的动态绑定

    有一个表单: <el-form :model="configForm"> </el-form> 如果configForm初始化为{},此对象是动态变化的,如 ...

  5. [转]网页ContentType详细列表

    本文转自:来老师的专栏   http://blog.csdn.net/sweetsoft/article/details/6512050 不同的ContentType 会影响客户端所看到的效果.默认的 ...

  6. 为Ubuntu安装SSH服务

    只有当Ubuntu安装了SSH服务后,我们才能够通过ssh工具登陆Ubuntu.我自己喜欢使用x-shell作为终端工具 1.安装Ubuntu缺省安装了openssh-client,所以在这里就不安装 ...

  7. CF985F Isomorphic Strings

    题目描述 You are given a string s s s of length n n n consisting of lowercase English letters. For two g ...

  8. 【题解】NOIP2016换教室

    哇好开心啊!写的时候真的全然对于这个加法没有把握,但还是大着胆子试着写了一下——竟然过了样例?于是又调了一下就过啦. 不过想想也觉得是正确的吧,互相独立的事件对于期望的影响自然也是相互独立的,可以把所 ...

  9. POJ 开关问题 解题报告

    开关问题 Time Limit: 1000MS Memory Limit: 30000K Description 有N个相同的开关,每个开关都与某些开关有着联系,每当你打开或者关闭某个开关的时候,其他 ...

  10. Generator的基本用法

    Generator函数是一个状态机,封装了多个内部状态.执行一个Generator,会返回一个迭代器对象,通过迭代器对象,可以遍历Generator函数内部的每个状态.因此,Generator函数可以 ...