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. iOS 带IAP提交注意事项及无法submit for review的解决方案

    原地址:http://blog.sina.com.cn/s/blog_71ce775e0101dl4a.html 最近项目接触到了苹果的程序内购(IAP),碰到不少问题,参考了很多帖子才得以解决.在此 ...

  2. Django——如何在Django模板中注入全局变量?——part2

    模版中的变量由context中的值来替换,如果在多个页面模版中含有相同的变量,比如:每个页面都需要{{user}},笨办法就是在每个页面的请求视图中都把user放到context中.   from d ...

  3. 【Excle】两个表格多列数据对比,找出差异

    现在有表格如下,差异A中的红色标记为区域1在区域2中找不到对应的值,差异B中的红色标记为区域2在区域1中找不到对应的值 那么怎么去查找呢? 这里用到COUNTIF跟数组公式 C3=SUM(COUNTI ...

  4. 利用pandas进行数据分析之ndarray结构

    Numpy的重要特点就是其N维数组对象, 1.ndarray每个元素是相同的,每个数组都有一个两个对象: .shape:用于表示维度大小的元组 .dtype:用户表示数组类型的对象 2.创建数组 ar ...

  5. linux-c 调试 gdb

    GDB(GNU Debugger) gcc -g –o testarg testarg.c //可执行文件中带上调试信息,用于后续的gdb调试 gdb testarg l; list //显示源程序 ...

  6. WCF RIA Services使用详解(转载)

    理解领域服务和领域操作 本文目录: 3.1 WCF Ria Services简介 3.1.1 什么是WCF Ria Services 3.1.2 WCF Ria Services如何生成客户端代码 3 ...

  7. 每天进步一点点——Linux中的文件描写叙述符与打开文件之间的关系

    转载请说明出处:http://blog.csdn.net/cywosp/article/details/38965239 1. 概述     在Linux系统中一切皆能够看成是文件,文件又可分为:普通 ...

  8. 李洪强漫谈iOS开发[C语言-001]-开发概述

  9. ajax请求后台返回map类型并如何展示

    前台jsp或者ftl文件接收返回结果: <input type="hidden" name="selectedModelListStr" id=" ...

  10. EEPlat的元模型体系

    EEPlat的元模型体系是元数据驱动的必要条件之中的一个.仅仅有通过元模型可以完好的描写叙述一个软件系统.才可以完整的定义该软件系统的元数据,也才干真正实现软件系统的元数据驱动式开发.也就意味着一个软 ...