2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Frequent Subsets Problem
来源:互联网 发布:apache服务器显示橙色 编辑:程序博客网 时间:2024/05/16 16:23
题目链接
- 1000ms
- 131072K
The frequent subset problem is defined as follows. Suppose U={1, 2,…,N} is the universe, and S1, S2,…,SM are M sets over U. Given a positive constant α, 0<α≤1, a subset B (B≠0) is α-frequent if it is contained in at least αM sets of S1, S2,…,SM, i.e. ∣{i:B⊆Si}∣≥αM. The frequent subset problem is to find all the subsets that are α-frequent. For example, let U={1,2,3,4,5}, M=3, α=0.5, and S1={1,5}, S2={1,2,5}, S3={1,3,4}. Then there are 3 α-frequent subsets of U, which are {1},{5} and {1,5}.
Input Format
The first line contains two numbers N and α, where N is a positive integers, and α is a floating-point number between 0 and 1. Each of the subsequent lines contains a set which consists of a sequence of positive integers separated by blanks, i.e., line i+1 contains Si, 1≤i≤M . Your program should be able to handle N up to 20and M up to 50.
Output Format
The number of α-frequent subsets.
样例输入
15 0.41 8 14 4 13 23 7 11 610 8 4 29 3 12 7 15 28 3 2 4 5
样例输出
11
题目来源
2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
题意:现在给你一个n,再给你不多于50组的数据(及大集合)(每一行算一组数据)(每组数据的数字个数未知,且无重复,且数字不大于n)现在让你求出,有多少个不同的 子集出现在这些集合中的概率大于a。
思路:数据不大,n最大20,最多50组数据;
第几组数据 1 2 3 4 5 ... (最多50组)
1 : 1 0 0 0 0
2 : 1 0 1 1 1
3 : 0 1 0 1 1
4 : 1 0 1 0 1
5 : 0 0 0 0 1
6 : 0 1 0 0 0
7 : 0 1 0 1 0
8 : 1 0 1 0 1
9 : 0 0 0 1 0
10 : 0 0 1 0 0
11 : 0 1 0 0 0
12 : 0 0 0 1 0
13 : 1 0 0 0 0
14 : 1 0 0 0 0
15 : 0 0 0 1 0
n : ..............
压缩成n个LL数字(横着看的二进制)
然后枚举所有的可能的子集合,把这个子集合所有对应的LL数字相与(&)后得到的数字转换成的二进制中1的个数就是包含这个子集合的大集合的个数
例1:存在子集{2,4,8}的大集合有多少个?
(1 0 1 1 1 )& (1 0 1 0 1)&(1 0 1 0 1)=(1 0 1 0 1)代表1,3,5组大集合中含有子集{2,4,8};
例2:存在子集{3,7}的大集合有多少个?
(0 1 0 1 1 )& (0 1 0 1 0)=(0 1 0 1 0)代表2,4组大集合中含有子集{3,7};
代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>#define LL long longusing namespace std;int a[55][25];LL d[25];char s[100];int ans=0;double ci;int LL1(LL x){ int sum=0; while(x) { if(x&1) sum++; x>>=1; } return sum;}void dfs(int x,int n,LL w){ if(LL1(w)<ci) return ; if(x>n) { ans++; return ; } dfs(x+1,n,w&d[x]); dfs(x+1,n,w); return ;}int main(){ memset(a,0,sizeof(a)); memset(d,0,sizeof(d)); int n,k=0; double m; scanf("%d%lf",&n,&m); getchar(); while(gets(s)) { int la=strlen(s); int sum=0; for(int i=0; i<la; i++) { if(s[i]==' ') { a[k][sum]=1; sum=0; continue; } sum=sum*10+s[i]-'0'; } a[k][sum]=1; k++; } ci=k*m-0.0000001; for(int j=1; j<=n; j++) for(int i=0; i<k; i++) d[j]=(d[j]<<1)+a[i][j]; dfs(1,n,(1LL<<51)-1);//(1LL<<51)-1代表二进制50个1(初始化) printf("%d\n",ans-1);}
另一种代码:
hash思想吧,把每组数据hash成一个数字。思想类似
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll long long#define lz 2*u,l,mid#define rz 2*u+1,mid+1,r#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-12;const int maxn=400005;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int a[101];int main(){ int n,x,i; double k; cin>>n>>k; n=(1<<n); mset(a,0); int top=1; while(scanf("%d",&x)!=EOF) { a[top]+=(1<<(x-1)); if(getchar()=='\n') top++; } int ans=0; for(i=1;i<n;i++) { int c=0; for(int j=1;j<=top;j++) { if((a[j]&i)==i) c++; } if(1.0*c/top>=k-esp) ans++; } cout<<ans<<endl; return 0;}
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛: M. Frequent Subsets Problem(状压)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem
- 2017 ACM-ICPC亚洲区(南宁赛区)网络赛 F.Frequent Subsets Problem
- Frequent Subsets Problem 进制运算 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Frequent Subsets Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:Frequent Subsets Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M Frequent Subsets Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem (状态压缩)
- 计蒜客 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 M. Frequent Subsets Problem (位压缩)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 The Heaviest Non-decreasing Subsequence Problem
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛:The Heaviest Non-decreasing Subsequence Problem
- 2017ACM-ICPC南宁网络赛Frequent Subsets Problem(康托展开+bfs)
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem (LIS)
- 素数表(Prime number table)
- Jzoj3443 压缩
- mac下 iterm+Zsh+Oh My Zsh+tmux 配置方案
- java 中解析json步骤
- 大数据预科班17
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Frequent Subsets Problem
- 数据结构——第一讲、基本概念(3)
- 104. Maximum Depth of Binary Tree (二叉树)
- 2017.9.23 C组比赛总结
- MFC_CSliderCtrl
- 双链表(java c/c++)
- ajax获取后台数据并插入到tr中 的功能实现
- 虹膜检测
- STM32F10X_LD、STM32F10X_MD、STM32F10X_HD、STM32F10X_CL