# 2017 ACM-ICPC 亚洲区（南宁赛区）网络赛 M. Frequent Subsets Problem （状态压缩）

599人阅读 评论(8)

The frequent subset problem is defined as follows. Suppose U={1, 2,\ldots,N} is the universe, and S_{1}S_{2},\ldots,S_{M}are M sets over U. Given a positive constant \alpha0<\alpha \leq 1, a subset B (B \neq 0) is α-frequent if it is contained in at least \alpha M sets of S_{1}S_{2},\ldots,S_{M}, i.e. \left | \left \{ i:B\subseteq S_{i} \right \} \right | \geq \alpha 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\alpha =0.5, and S_{1}=\{1, 5\}S_{2}=\{1,2,5\}S_{3}=\{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 \alpha, where N is a positive integers, and \alpha 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 S_{i}1 \le i \le M . Your program should be able to handle N up to 20 and M up to 50.

### Output Format

The number of \alpha-frequent subsets.

#### 样例输入

15 0.4
1 8 14 4 13 2
3 7 11 6
10 8 4 2
9 3 12 7 15 2
8 3 2 4 5

#### 样例输出

11

#### 题目来源

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

1
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：52997次
• 积分：1971
• 等级：
• 排名：千里之外
• 原创：149篇
• 转载：1篇
• 译文：0篇
• 评论：16条
联系方式
欢迎谈论交流：1245985209
友情链接_winter2121
http://blog.csdn.net/winter2121
友情链接_anoxiacxy
https://anoxiacxy.github.io/
博客专栏
 CodeForce题解 文章：37篇 阅读：14470
 ACM的进阶之路 文章：80篇 阅读：31841
文章分类