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. MPTCP 源码分析(七) 拥塞控制

    简述      MPTCP的拥塞控制对TCP的拥塞控制的线性增加阶段进行了修改,而慢启动,快速重传. 快速恢复都没有改变.每条子路径拥有自己的cwnd,MPTCP的拥塞算法主要关心cwnd的改变.   ...

  2. 火狐浏览器获取event

    因为各种浏览器对js文件的解析不同.加上各种浏览器的内核不一样,以及内核版本号也不一样,所以获取event的方式也不一样. 使用原始的方式获取event是 这种: document.body.oncl ...

  3. UICollectionViews有了简单的重排功能

    代码地址如下:http://www.demodashi.com/demo/13213.html 一.前言 我是UICollectionView的忠实粉丝.这个类比起它的老哥UITableView类具有 ...

  4. c++ builder xe2 字符串转日期

    TFormatSettings * fmt = new TFormatSettings; fmt->ShortDateFormat = L"yy-mm-dd"; fmt-&g ...

  5. C# 播放H264裸码流

    要播放H264裸码流,可以分拆为以下三个工作: 1.解码H264裸码流获取YUV数据 2.将YUV数据转换为RGB数据填充图片 3.将获取的图片进行显示 要完成工作1,我们可以直接使用海思的解码库,由 ...

  6. [DevExpress]XtraTabControl右键加入关闭当前页、关闭其它页、所有关闭的实现

    private void xtraTabControl_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButton ...

  7. php中的正则表达式

    一.定位字符 定位字符是正则表达式中又一类非常重要的字符,它的主要作用是用于对字符在匹配对象中的位置进行描述. ^:表示匹配的模式出现在匹配对象的开头(和在"[]"里面不同) $: ...

  8. 通过WSDL命令,将WSDL生成代理类

    VS2010 打开命令行窗口(开始-VS2010--Visual Studio Tools--Visual Studio Command Prompt) 输入: wsdl  /l:cs /n:newN ...

  9. Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本

    Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本 1. clipse提供了UML的底层Java包, 1 2. MDTUML2Getting St ...

  10. 严重: Error in dependencyCheck java.io.IOException: invalid header field(tomcat启动成功可是訪问web项目404错误)

    tomcat启动的时候出现 严重: Error in dependencyCheck java.io.IOException: invalid header field 而且tomcat也不自己主动r ...