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;
}


 

2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys的更多相关文章

  1. GYM 101064 2016 USP Try-outs G. The Declaration of Independence 主席树

    G. The Declaration of Independence time limit per test 1 second memory limit per test 256 megabytes ...

  2. 【Codeforces Round #424 (Div. 2) D】Office Keys

    [Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都 ...

  3. Codeforces663E Binary Table(FWT)

    题目 Source http://codeforces.com/contest/663/problem/E Description You are given a table consisting o ...

  4. [gym100956]Problem J. Sort It! BIT+组合数

    source : Pertozavodsk Winter Training Camp 2016 Day 1: SPb SU and SPb AU Contest, Friday, January 29 ...

  5. C - Haiku

    Problem description Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syl ...

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

  7. 【Codeforces Round 725】Canada Cup 2016

    模拟Canada Cup 2016,ABC三题,Rank1376 第三题卡住了 Codeforces 725 C 求出两个相同字符的位置,记为x和y. 然后考虑把相同的那个字符放在第一行的什么地方, ...

  8. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  9. 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) E

    链接:http://codeforces.com/gym/101116 学弟写的,以后再补 #include <iostream> #include <algorithm> # ...

  10. 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended) J

    链接:http://codeforces.com/gym/101116 题意:给出n个点,要求一个矩形框将(n/2)+1个点框住,要面积最小 解法:先根据x轴选出i->j之间的点,中间的点(包括 ...

随机推荐

  1. oracle初级(续)

    有志者.事竟成,破釜沉舟,百二秦关终属楚: 苦心人.天不负,卧薪尝胆,三千越甲可吞吴. oracle基本简单的用法,之前的笔记稍作整理一下,希望对各位有用,如有问题可在下方留言,所有SQL都是经过or ...

  2. windows 下共享内存使用方法示例

    windows下共享内存使用方法较 linux 而言微微复杂 示例实现的功能 有一个视频文件,一块内存区域 : 程序 A,将该视频写入该内存区域 : 程序 B,从该内存区域读取该视频 : 代码模块实现 ...

  3. discuz管理员登录进入后台管理马上跳转到登录界面

    昨天尝试了一下这个discuz论坛,感觉还可以.今天刚刚用管理员账户进入后台管理,准备改一改界面熟悉一下,过不了10秒钟.老是马上就退出来了.我想起来了,昨天是在阿里云服务器上面直接登录这个管理员账号 ...

  4. 转载|chrome developer tool—— 断点调试篇

    断点,调试器的功能之一,可以让程序中断在需要的地方,从而方便其分析.也可以在一次调试中设置断点,下一次只需让程序自动运行到设置断点位置,便可在上次设置断点的位置中断下来,极大的方便了操作,同时节省了时 ...

  5. CentOS7 nginx安装

    1 nginx安装环境 nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境. n gcc 安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没 ...

  6. ElasticSearch 学习记录之ES高亮搜索

    高亮搜索 ES 通过在查询的时候可以在查询之后的字段数据加上html 标签字段,使文档在在web 界面上显示的时候是由颜色或者字体格式的 GET /product/_search { "si ...

  7. C/C++调用Golang 二

    C/C++调用Golang 二 <C/C++调用Golang 一>简单介绍了C/C++调用Golang的方法步骤,只涉及一个简单的函数调用.本文总结具体项目中的使用场景,将介绍三种较复杂的 ...

  8. mysql数据库出现2003-Can't connect to MySQL server on 'localhost' (10061)的解决方法

    1.右键点击我的电脑,找到管理! 2.找到服务和应用程序: 3.打开找到服务,打开: 4.在服务里找到MySQL,改成启动:

  9. linux系统下phpstudy里的mysql使用方法

    linux作为一个优秀的服务器端管理系统,其实linux的桌面系统也用起来十分的nice.好吧,如何你在做开发的时候在linux下安装了lmap或者phpstudy,那么在第一次使用其自带的mysql ...

  10. 【转】String Date Calendar之间的转换

    1.Calendar 转化 String Calendar calendat = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDa ...