C.Sleep Buddies

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 ≤ 105, 1 ≤ 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

代码:

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e5 + ;
int main()
{
int t,k=,n,x,a[M],m,p[];
ll b[M];
double dd;
scanf("%d%d",&t,&m);
for(int i=;i<=m+;i++){
p[i] = pow(,i-);
}
memset(b,,sizeof(b));
while(t--){
scanf("%d",&n);
memset(a,,sizeof(a));
for(int i = ;i < n;i++){
scanf("%d",&x);
a[x] = ;
}
int ans = ;
for(int i=;i<=m;i++){
ans += (p[i]*a[i]);
}
//cout<<ans<<endl;
b[ans]++;
} //设一个十进制的数,b数组是因为总共不超过1024,然后他有1e5的集合,有重复;
cin>>dd;
int c[];
for(int k=;k<=m;k++)
c[k]=pow(,k-);
ll sum = ;
for(int i = ;i <= p[m+]; i++){
for(int j = i;j <= p[m+]; j++){
int num1 = (i|j),num2=(i&j);
double cnt1=,cnt2=;
for(int k=;k<=m;k++)
{
if(num1&c[k])
cnt1++;
if(num2&c[k])
cnt2++;
}
//cout<<cnt1/cnt2<<endl;
if(cnt2/cnt1>=dd&&i!=j&&b[i])
sum+=b[i]*b[j];
else if(cnt1/cnt2>=dd&&i==j&&b[i]){
sum+=b[i]*(b[i]-)/;
}
}
}
cout<<sum<<endl;
}


 

Codeforces Gym101063 C.Sleep Buddies (2016 USP-ICMC)的更多相关文章

  1. Codeforces Gym101063 J.The Keys (2016 USP-ICMC)

    J.The Keys Out of all science labs constructed by the GEMA mission on Mars, the DSL - Dangerous Spec ...

  2. Codeforces Gym101063 F.Bandejao (2016 USP-ICMC)

    F.Bandejao It is lunch time on Mars! Everyone has got that big smile on their faces, all eager to se ...

  3. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths

    题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...

  4. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C - Bear and Colors

    题目链接: http://codeforces.com/contest/673/problem/C 题解: 枚举所有的区间,维护一下每种颜色出现的次数,记录一下出现最多且最小的就可以了. 暴力n*n. ...

  5. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  6. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造

    D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...

  7. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力

    C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...

  8. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B. Problems for Round 水题

    B. Problems for Round 题目连接: http://www.codeforces.com/contest/673/problem/B Description There are n ...

  9. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题

    A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...

随机推荐

  1. python PEP8代码规范及问题

    最近刚刚接触Python,为了养成好习惯,尽量保证自己写的代码符合PEP8代码规范,下面是过程中报出的警告及解决方法,英文有些翻译不太准确见谅,会不断更新: PEP 8: module level i ...

  2. 2016-2017 ACM-ICPC CHINA-Final

    A Gym 101194A Number Theory Problem 7 的二进制是111,2k-1 的二进制是 k 个 1.所以 k 能被 3 整除时 2k-1 才能被 7 整除. #includ ...

  3. HDU 3368 Reversi

    http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...

  4. 4444: [Scoi2015]国旗计划

    4444: [Scoi2015]国旗计划 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 485  Solved: 232 Description A国 ...

  5. 【MySQL】资源列表

    1.使用yum方式安装MySQL https://blog.csdn.net/zl570932980/article/details/78934601 2.安装Xtrabackup备份工具 https ...

  6. Boost入门

    [转载网友转载的 不过不知道原作者地址] Boost入门向导 简介:boost是一套开源的.高度可移植的C++模板库.它由C++标准委员发起,且里面很多组件有望成为下一代的C++标准库,其地位将会与S ...

  7. 16进制转10进制 HDU-1720

    A+B Coming Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. k8s与CICD--借助scp插件实现非容器项目的部署

    一直没有时间完成drone系列文章.drone-wechat插件实现了一半,由于企业微信token申请比较麻烦,所以也没有进展.今天抽出时间,研究了一下scp插件,主要目的是实现非容器项目的部署.其实 ...

  9. HDU 4180 扩展欧几里得

    RealPhobia Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. call、apply与bind在理解

    call() 方法在使用一个指定的 this 值和若干个指定的参数值的前提下调用某个函数或方法. fun.call(thisArg[, arg1[, arg2[, ...]]]) apply() 方法 ...