• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

hdu3006之位压缩

 

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;
}

 

posted @ 2013-08-18 21:57  Class Xman  阅读(124)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3