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. iOS 获取当前应用的信息以及用户信息:版本号手机号手机型号

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // ap ...

  2. 动态WebApi

    动态WebApi实现了直接对Service的调用,其实没有跨过ApiController,只是我们自己创建出ApiController 实现主要分以下几步 一 对默认WebApi服务的替换 ApiGl ...

  3. find 命令详解

    find 作用:用于在文件树种查找文件,并作出相应的处理 (硬盘) 格式:find pathname -options [-print -exec -ok ...] 格式参数:pathname: fi ...

  4. 面向对象 初级版 (Preview) 未完

    概述: 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数里,日后使用无需重复编写,直接调用韩顺即可. 面向对象: 对函数进行分类和封装,让开发'更快更强' 面向对象和面向过程的通 ...

  5. 第九章 BootstrapTable的使用

    一.简介 BootstrapTable是一个Bootstrap 3 的表格插件,支持单选, 复选框, 排序, 分页等功能 官网:http://bootstrap-table.wenzhixin.net ...

  6. pythonseleniumAPI

    一.浏览器操作 1.浏览器最大化 driver.maximize_window() #将浏览器最大化显示 2.设置浏览器宽.高 driver.set_window_size(480, 800)#设置浏 ...

  7. Python函数参数的五种类型

    之前项目需求,需要通过反射获取函数的参数,python中可以通过函数签名(signature)来实现. 首先需要了解函数参数的类型,Python的参数类型一共有5种:POSITIONAL_OR_KEY ...

  8. shell脚本的if语句,判断某程序是否存在,不存在启动该程序!

    想必大家都知道 "如果......那么......" 这种语法的应用吧! 当然呢,linux下对于这种用法也是有所考虑的,很多时候我们都需要写一个shell脚本,难免会避免if语句 ...

  9. 代码审计之XiaoCms(后台任意文件上传至getshell,任意目录删除,会话固定漏洞)

    0x00 前言 这段时间就一直在搞代码审计了.针对自己的审计方法做一下总结,记录一下步骤. 审计没他,基础要牢,思路要清晰,姿势要多且正. 下面是自己审计的步骤,正在逐步调整,寻求效率最高. 0x01 ...

  10. Java 写三角形 空心三角形 菱形 空心菱形

    闲来无事,练习了一下Java基础中的循环语句.练习循环语句,当然少不了,用*打印出来三角形.空心三角形.菱形等这样的几何图形. 粗心大意,失误两次: 一.三角形 遇到一些小问题: 二.金字塔 由于三角 ...