http://acm.hdu.edu.cn/showproblem.php?pid=3006

题意

给定n个集合,每个集合都是由大于等于1小于等于m的数字组成,m最大为14。问由给出的集合可以组成多少个不同的集合。

分析

因为m最大为14位,那么可以把一个集合压缩成一个数,每个元素对应二进制的一个位。所有状态最大为(1<<m)。用个数组记录出现的状态,用map实测超时。

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#include<bitset>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
const int N = 1e6+;
//const int MAXN = 210;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T;
void testcase(){
printf("Case #%d: ",++T);
}
const int MAXN = +;
const int MAXM = 5e5+;
int ma[MAXM];
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int n,m,x,y,value;
while(~scdd(n,m)){
mset(ma,);
int ans=;
for(int i=;i<n;i++){
scd(x);
value=;
for(int j=;j<x;j++){
scd(y);
value+=(<<(y-));
}
ma[value]=;
for(int j=;j <= (<<m) ;j++){
if(ma[j]){
ma[j|value]=;
}
} } for(int i=;i<=(<<m);i++) if(ma[i]) ans++;
cout<<ans<<endl;
}
return ;
}

HDU - 3006 The Number of set(状态压缩位运算)的更多相关文章

  1. uva 1601 poj 3523 Morning after holloween 万圣节后的早晨 (经典搜索,双向bfs+预处理优化+状态压缩位运算)

    这题数据大容易TLE 优化:预处理, 可以先枚举出5^3的状态然后判断合不合法,但是由于题目说了有很多墙壁,实际上没有那么多要转移的状态那么可以把底图抽出来,然后3个ghost在上面跑到时候就不必判断 ...

  2. hdu3006 状态压缩+位运算+hash(小想法题)

    题意:        给了n个集合,问你这n个集合可以组合出多少种集合,可以自己,也可以两个,也可以三个....也可以n个集合组在一起. 思路:       是个小想法题目,要用到二进制压缩,位运算, ...

  3. hdu 4057 AC自己主动机+状态压缩dp

    http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...

  4. HDU 3006 The Number of set(位运算 状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3006 题目大意:给定n个集合,每个集合都是由大于等于1小于等于m的数字组成,m最大为14.由给出的集合 ...

  5. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  6. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  7. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

  8. HDU 5025 Saving Tang Monk 【状态压缩BFS】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Time Limit: 2000/1000 MS (Java/O ...

  9. HDU 5418——Victor and World——————【状态压缩+floyd】

    Victor and World Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Other ...

随机推荐

  1. Debian中APT的前世今生

    https://baike.baidu.com/item/apt-get/2360755 https://www.debian.org/doc/manuals/debian-handbook/sect ...

  2. Navicat连接mysql备份数据库提示:1577 – Cannot proceed because system tables used by Event Scheduler where found damaged at server start

    解决办法,可以参考试试: http://www.cnblogs.com/huangcong/p/3389010.html http://blog.csdn.net/phpfenghuo/article ...

  3. Java-System.getProperty()

    Java平台使用了一个Poperties对象来维护其自己的配置信息.System泪中包含有一个Properties对象用于描述当前工作环境的配置.系统properties包含了关于当前用户.当前Jav ...

  4. MiniDP与HDMI的关系

    高清输出革命先行者:HDMI接口 HDMI高清晰度多媒体接口(英文:High Definition Multimedia Interface,HDMI)是一种数字化视频/音频接口技术,是适合影像传输的 ...

  5. Highcharts之折线图

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. php-编译模块1

    在路径中找到phpize 在需要编译的模块文件夹中执行 如: /usr/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Modul ...

  7. java 获取 T.class

    转载:http://www.hankcs.com/program/t-class.html @Test public void Test() throws Exception{ Foo<User ...

  8. MT【12】三点坐标求面积

    $L_1,L_2$是O发出的两条射线,C是一个常数,一条动直线$l$分别与$L_1,L_2$交于A,B两点.$S_{\Delta ABC}=C$,求A,B的中点D的轨迹方程.(2012北大自主招生) ...

  9. 自学Linux Shell14.3-创建临时文件

    点击返回 自学Linux命令行与Shell脚本之路 14.3-创建临时文件mktemp Linux系统保留了一个特殊的目录位置,以供临时文件使用.Linux使用/tmp目录处理不需要永久保存的文件. ...

  10. 自学Zabbix7.1 IT services

    自学Zabbix7.1 IT services 1. 概念IT Services 服务器或者某项服务.业务的可用率,不懂技术的上级领导会过问最近服务器可用率如何.所有api的状况怎么样?通常一些技术人 ...