题意:https://nanti.jisuanke.com/t/17320

The frequent subset problem is defined as follows. Suppose U={1, 2,…\ldots…,N} is the universe, and S1S_{1}S1​​, S2S_{2}S2​​,…\ldots…,SMS_{M}SM​​ are MMM sets over UUU. Given a positive constant α\alphaα, 0<α≤10<\alpha \leq 10<α1, a subset BBB (B≠0B \neq 0B0) is α-frequent if it is contained in at least αM\alpha MαM sets of S1S_{1}S1​​, S2S_{2}S2​​,…\ldots…,SMS_{M}SM​​, i.e. ∣{i:B⊆Si}∣≥αM\left | \left \{ i:B\subseteq S_{i} \right \} \right | \geq \alpha M∣{i:B⊆S​i​​}∣≥αM. The frequent subset problem is to find all the subsets that are α-frequent. For example, let U={1,2,3,4,5}U=\{1, 2,3,4,5\}U={1,2,3,4,5}, M=3M=3M=3, α=0.5\alpha =0.5α=0.5, and S1={1,5}S_{1}=\{1, 5\}S​1​​={1,5}, S2={1,2,5}S_{2}=\{1,2,5\}S​2​​={1,2,5}, S3={1,3,4}S_{3}=\{1,3,4\}S​3​​={1,3,4}. Then there are 333 α-frequent subsets of UUU, which are {1}\{1\}{1},{5}\{5\}{5} and {1,5}\{1,5\}{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 SiS_{i}Si​​, 1≤i≤M1 \le i \le M1iM . Your program should be able to handle NNN up to 202020 and MMM up to 505050.

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<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 500
int a[N];
int main()
{
    int n,ans=0,x;
    double m;
    char r;
    scanf("%d%lf",&n,&m);

    while(scanf("%d%c",&x,&r)!=EOF)
    {
        a[ans]+=1<<(x-1);
        if(r=='\n')
            ans++;
    }
    int w=ceil(m*ans);
    int sum=0;
    for(int i=1;i<(1<<n);i++)
    {
        int t=0;
        for(int j=0;j<ans;j++)
        {
            if((i & a[j]) ==i) t++;///优先级  要带括号
        }
        if(t>=w)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}

 

posted on 2017-10-26 10:11  云胡不喜。  阅读(178)  评论(0编辑  收藏  举报