Sleep Buddies

time limit per test

2.0 s

memory limit per test

256 MB

input

standard input

output

standard output

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 andB 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.

Examples

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 个集合,全集为 1 -- m 的整数,然后一个比率 k , 然后问,每两个的集合交集元素个数除并集元素个数大于 k 的个数有多少

//注意到,全集 m 非常小,所以,可以用二进制来表示某个数有没有,这样,每个数都能代表一个集合,最多也就 2^10 = 1024 个

统计数量,暴力二重循环计数即可,又犯了个错,浮点数的大于等于,一定要理解!!!

 # include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <sstream>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define LL long long
# define pr pair
# define mkp make_pair
# define lowbit(x) ((x)&(-x))
# define PI acos(-1.0)
# define INF 0x3f3f3f3f3f3f3f3f
# define eps 1e-
# define MOD inline int scan() {
int x=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-; ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
inline void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
# define MX
/**************************/ int n,m;
int st[MX]; LL C(LL a,LL b)
{
if (b<) return ;
return b*(b-)/;
} double gai(int a,int b)
{
int all = ;
int jiao =;
for (int i=;i<m;i++)
{
if ( (a&(<<i)) || (b&(<<i)) ) all++;
if ( (a&(<<i)) && (b&(<<i)) ) jiao++;
}
return (jiao*1.0)/all;
} int main()
{ while (scanf("%d%d",&n,&m)!=EOF)
{
memset(st,,sizeof(st));
for (int i=;i<=n;i++)
{
int num;
scanf("%d",&num);
int sb=;
for (int j=;j<=num;j++)
{
int x;
scanf("%d",&x);
sb = (sb ^ (<<(x-)));
}
st[sb]++;
}
double p;
scanf("%lf",&p); LL ans = ;
int ut = (<<m);
for (int i=;i<ut;i++)
{
for (int j=i;j<ut;j++)
{
if (gai(i,j)-p>-eps)
{
if (i==j) ans = ans+C(,st[i]);
else ans = ans+((LL)st[i])*st[j];
}
}
}
cout<<ans<<endl;
}
return ;
}

Sleep Buddies的更多相关文章

  1. 2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys

    Gym101063C-Sleep Buddies It is nighttime in the Earth Colony on Mars and everyone is getting ready t ...

  2. uva 12356 Army Buddies 树状数组解法 树状数组求加和恰为k的最小项号 难度:1

    Nlogonia is fighting a ruthless war against the neighboring country of Cubiconia. The Chief General ...

  3. Codeforces Gym101063 C.Sleep Buddies (2016 USP-ICMC)

    C.Sleep Buddies It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. ...

  4. PyQt学习随笔:Qt Designer的Edit Buddies功能

    在Qt Designer的Edit菜单下有个Edit Buddies(编辑伙伴关系)子菜单,该菜单的作用是将一个Label与其他控件关联起来,当Label控件设置了快捷键时,通过Label的快捷键就可 ...

  5. uva 12356 Army Buddies

    简单的并查集应用. #include<stdio.h> #include<string.h> #include<math.h> #include<algori ...

  6. Java:泛型基础

    泛型 引入泛型 传统编写的限制: 在Java中一般的类和方法,只能使用具体的类型,要么是基本数据类型,要么是自定义类型.如果要编写可以应用于多种类型的代码,这种刻板的限制就会束缚很多! 解决这种限制的 ...

  7. 黑马----JAVA泛型基础

    黑马程序员:Java培训.Android培训.iOS培训..Net培训 JAVA范型-基础 一.泛型的概念 1.实现了参数化类型 2.用于编写可应用于多种类型的代码,即所编写的代码可应用于许多许多的类 ...

  8. java 泛型编程学习

    先发布,以后有空再修改... 第一次看到<java核心技术卷一>中关于泛型这部分的时候感觉很复杂,似乎有说不完的约束条件,让人难以理解.当时只是囫囵吞枣般过了一遍,也没有看出个什么来.现在 ...

  9. 《程序设计教学法--以Java程序设计为例》

    <程序设计教学法--以Java程序设计为例> 当老师上的第一门课就是<Java程序设计>,工作以来,断断续续上了近十次课了吧.十几年来,教材.课程内容.教学方法.教学手段不断改 ...

随机推荐

  1. Request.Cookies使用方法分析

    本文章介绍了Request.Cookies的基本的语法和使用方法. 而且通过演示样例分析了Request.Cookies的使用过程. Request.Cookies方法能够检索Cookies 集合中的 ...

  2. 查看tomcat启动文件都干点啥---catalina.bat

    在上一次查看tomcat启动文件都干点啥一文中,我们总结出,startup.bat文件的作用就是找到catalina.bat文件,然后把参数传递给它,在startup.bat中,调用catalina. ...

  3. 在线激活Pycharm(亲测有效)

    (1)在激活界面的License server输入:http://idea.liyang.io:或者:点击help→Register→License sever ,输入http://idea.liya ...

  4. 阿里云dataworks数据工场用户使用子账号

    如果您是第一次使用子账号登录数加平台和使用DataWorks,您需要获知以下内容: 该子账号所属主账号的企业别名. 该子账号的用户名和密码. 该子账号的AccessKey ID和AccessKey S ...

  5. 牛散NO.2:MACD西施说风情,柳下惠高位勿迷情

    创业板日线“高位夺命勾魂枪” 话说在创业板的波段调整中,MACD的勾魂枪同样让多头“魂断蓝桥”.圈内图形又好比西施姑娘回眸一笑,吴王夫差便注定命赴黄泉了.范蠡的精心设计让西施 布了一个风情万种的局,被 ...

  6. Web服务器性能/压力测试工具http_load、webbench、ab、Siege、loadrunner

    回头看看 Web服务器性能/压力测试工具http_load.webbench.ab.Siege.loadrunner

  7. SpringCloud系列六:Eureka的自我保护模式、IP选择、健康检查

    1. 回顾 前面讲了很多Eureka的用法,比如Eureka Server.Eureka Server的高可用.Eureka Server的用户认证(虽然未完全实现).元数据等, 这章将讲解剩下的自我 ...

  8. FPGA和DSP间基于SRIO的高速通信系统设计

    作者:陈婷,岳强,汪洋 解放军信息工程大学 摘要: 现代信号处理系统通常需要在不同处理器之间实现高速数据通信,SRIO协议由于高效率.低延时的特性被广泛使用.本文研究了在FPGA和DSP两种处理器之间 ...

  9. Windows GDI 映射模式(出自:Windows程序设计第5版-珍藏版)

    GDI映射模式(mapping mode):和映射模式紧密相关的还有4个其它的设备环境属性:1.窗口原点(window origin)2.视口原点(viewport origin)3.窗口范围(win ...

  10. 配置HADOOP_HOME

    配置HADOOP_HOME export HADOOP_HOME=/usr/hadoop-1.2.0export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sb ...