HDU - 3006 The Number of set(状态压缩位运算)
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(状态压缩位运算)的更多相关文章
- uva 1601 poj 3523 Morning after holloween 万圣节后的早晨 (经典搜索,双向bfs+预处理优化+状态压缩位运算)
这题数据大容易TLE 优化:预处理, 可以先枚举出5^3的状态然后判断合不合法,但是由于题目说了有很多墙壁,实际上没有那么多要转移的状态那么可以把底图抽出来,然后3个ghost在上面跑到时候就不必判断 ...
- hdu3006 状态压缩+位运算+hash(小想法题)
题意: 给了n个集合,问你这n个集合可以组合出多少种集合,可以自己,也可以两个,也可以三个....也可以n个集合组在一起. 思路: 是个小想法题目,要用到二进制压缩,位运算, ...
- hdu 4057 AC自己主动机+状态压缩dp
http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...
- HDU 3006 The Number of set(位运算 状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3006 题目大意:给定n个集合,每个集合都是由大于等于1小于等于m的数字组成,m最大为14.由给出的集合 ...
- HDU 1074 Doing Homework (dp+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...
- hdu 4336 Card Collector(期望 dp 状态压缩)
Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...
- HDU 5724 Chess(SG函数+状态压缩)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...
- 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 ...
- HDU 5418——Victor and World——————【状态压缩+floyd】
Victor and World Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Other ...
随机推荐
- Sonatype Nexus 2.11.1-01 使用入门
nexus安装与启动 linux下: 安装路径 /home/maven/nexus-2.11.1-01/ 启动方法 ./bin/nexus start windows下: 管理员模式运行cmd.exe ...
- asp.net core 2.0中的配置(1)---Configuration
配置就是一个装配数据字典的过程,一个字典也就是一个键值对,所以从配置就是键值对. 在asp.net core中关于配置是由四个基本的类型来支撑的,是①IConfigurationSource②ICon ...
- ESXi 更新补丁 暂时未测试 等有时间尝试一下.
下载地址: https://my.vmware.com/group/vmware/patch 使用操作图: 选择相应的zip包下载即可 更新方式: 命令方式升级ESXi主机补丁包 1.进入VMware ...
- C1考试科目一知识总结
第二 交通信号 交通信号灯 机动车信号灯(红灯停,路灯走,黄灯等) 车道信号灯(绿色箭头表示该车道通行,红色箭头和红叉表示该车道禁止通行) 方向指示信号灯(红色箭头表示该方向禁止通行,绿色箭头表示该方 ...
- 自学Linux Shell12.4-for命令
点击返回 自学Linux命令行与Shell脚本之路 12.4-for命令 1. for命令 格式一 for var in list do commands done 格式二 for var in li ...
- BZOJ 4009: [HNOI2015]接水果
4009: [HNOI2015]接水果 Time Limit: 60 Sec Memory Limit: 512 MBSubmit: 636 Solved: 300[Submit][Status] ...
- SharePoint “File not found” 错误
Troubleshooting the SharePoint "File not found" Error Have you ever come across a "Fi ...
- CPP--借助神器VS理解内存存储(含大小端对齐)
单位,补码之类的可以看这个:http://www.cnblogs.com/dotnetcrazy/p/8178175.html 先说说大小端对齐的事情,然后再看: 内存最小单位==>Byte,i ...
- CF 1023
昨天晚上打的一场CF,口胡一下前4题吧. A要注意细节,先找*,如果没有就判两者相等. 然后注意长度n - 1 <= m,然后前后比较,最后判断中间是不是字母. B先判断有没有解,然后求出 k ...
- A1102. Invert a Binary Tree
The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ( ...