码迷,mamicode.com
首页 > 其他好文 > 详细

C - Sleep Buddies Gym - 101063C 状压

时间:2017-07-29 16:28:14      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:ring   多少   card   required   eps   tar   分享   color   image   

C - Sleep Buddies Gym - 101063C 

题目链接:

https://vjudge.net/problem/473487/origin

Description:

It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. It is common to sleep in pairs, so that if anything were to happen during the night people could aid each other.

To decide who is a suitable candidate to sleep with whom, the leaders of GEMA asked everyone to answer a questionnaire about attributes they desire their partner to have from a list of M possible items.

To choose the pairs, GEMA uses the Jaccard index between the desired attributes of both persons. The Jaccard index for two sets A and B is defined as 技术分享, that is, the size of the intersection between A and B divided by the size of their union. They allow a pair to be formed if the Jaccard index of the two attribute sets for the pair is at least K.

Thanks to GEMA, there are too many people living on Mars these days. Help the high commanders decide how many allowed pairs there are out of the N people living there.

Input

The input begins with two integers, N and M (1?≤?N?≤?1051?≤?M?≤?10), the number of people on Mars and the number of possible attributes on the questionnaire.

Then follow N lines, each beginning with an integer Q (1?≤?Q?≤?M), the number of desired attributes on the list of the i-th person. Then follow Q integers q (1?≤?q?≤?M), encoding these attributes. There numbers are all different.

The last line of input contains a real number K (0?≤?K?≤?1), the minimum required Jaccard index for a pair.

Output

Output the number of pairs that are allowed.

Example

Input
2 5
2 1 3
5 3 1 5 4 2
0.66489
Output
0
Input
3 1
1 1
1 1
1 1
0.85809
Output
3
题意:
N个人,M种属性,每个人有Qi个性属性,分pair要求两个人的

技术分享 >=K,问有多少对人满足。
Hint:
M只有10,考虑状压,二进制位保存没有这种属性。
AC代码:
#include<bits/stdc++.h>
#define LL long long
#define maxn 100010
#define eps 1e-6
using namespace std;
int n,m,q,Q;
LL vis[maxn];
LL num[maxn];
double k;
set<int> s;
vector<int> G[20];
int solve(int x){
    int res=0;
    while(x>0){
        if(x&1)
            res++;
        x>>=1;
    }
    return res;
}
int main(){
    cin>>n>>m;
    int now=0,Q;
    for(int i=1;i<=n;i++){
        scanf("%d",&Q);
        now=0;    
        for(int j=1;j<=Q;j++){
            scanf("%d",&q);
            now+=(1<<(q-1));
        }    
        s.insert(now);
        vis[now]++;
    }
    cin>>k;
    LL ans=0;
    LL aa,bb;
    for(int i=0;i<(1<<10);i++){
        if(vis[i]==0) continue;
        for(int j=i+1;j<(1<<10);j++){
            if(vis[j]==0) continue;
            now=(i&j);
            aa=solve(now);
            bb=solve(i)+solve(j)-solve(now);
            if((double)aa/bb>=k){
                ans+=(vis[i]*vis[j]);
            }
        }
        aa=vis[i];
        if(aa>=2){
            ans+=(aa*(aa-1))/2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

 

 

 

C - Sleep Buddies Gym - 101063C 状压

标签:ring   多少   card   required   eps   tar   分享   color   image   

原文地址:http://www.cnblogs.com/poler/p/7255897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!