C. Felicity is Coming!
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving.

Formally, an evolution plan is a permutation f of {1, 2, ..., m}, such that f(x) = y means that a Pokemon of type x evolves into a Pokemon of type y.

The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol.

Two evolution plans f1 and f2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an i such that f1(i) ≠ f2(i).

Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109 + 7.

Input

The first line contains two integers n and m (1 ≤ n ≤ 105, 1 ≤ m ≤ 106) — the number of gyms and the number of Pokemon types.

The next n lines contain the description of Pokemons in the gyms. The i-th of these lines begins with the integer gi (1 ≤ gi ≤ 105) — the number of Pokemon in the i-th gym. After that gi integers follow, denoting types of the Pokemons in the i-th gym. Each of these integers is between 1 and m.

The total number of Pokemons (the sum of all gi) does not exceed 5·105.

Output

Output the number of valid evolution plans modulo 109 + 7.

Examples
input
2 3
2 1 2
2 2 3
output
1
input
1 3
3 1 2 3
output
6
input
2 4
2 1 2
3 2 3 4
output
2
input
2 2
3 2 2 1
2 1 2
output
1
input
3 7
2 1 2
2 3 4
3 5 6 7
output
24
Note

In the first case, the only possible evolution plan is:

In the second case, any permutation of (1,  2,  3) is valid.

In the third case, there are two possible plans:

In the fourth case, the only possible evolution plan is:


题目连接:http://codeforces.com/problemset/problem/757/C

题意:一个全排列变换f,f[i]为把i变成f[i]。有n个gym,m种口袋妖怪。现在要讲口袋妖怪进行变换,变换前后每个gym里面的口袋妖怪数量和种类一样。求变换的种类。

思路:x——>y,则x所在的gym集合与y所在的gym集合一样。vector[i] 为种类i的的gym集合。sort后进行比较。

代码:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int MAXN=1e6+,mod=1e9+;
vector<int>v[MAXN];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
int g;
scanf("%d",&g);
for(int j=; j<=g; j++)
{
int x;
scanf("%d",&x);
v[x].push_back(i);
}
}
sort(v+,v+m+);///涨姿势了!
/*
for(int i=1;i<=m;i++)
{
for(int j=0;j<v[i].size();j++)
cout<<v[i][j]<<" ";
cout<<endl;
}
*/
__int64 ans=;
int t=;
for(int i=; i<=m; i++)
{
if(v[i]==v[i-])
{
t++;
ans=(ans*t)%mod;
}
else t=;
}
cout<<ans<<endl;
return ;
}

用sort对vector数组排序

感谢巨巨的分享:http://blog.csdn.net/jeremy1149/article/details/54407467

Codeforces 757C. Felicity is Coming!的更多相关文章

  1. 【codeforces 757C】Felicity is Coming!

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Codeforces 757D - Felicity's Big Secret Revealed

    757D - Felicity's Big Secret Revealed 题目大意:给你一串有n(n<=75)个0或1组成的串,让你划最多n+1条分割线,第一条分割线的前面和最后一条分割线的后 ...

  3. CodeForces 757D Felicity's Big Secret Revealed(状压DP)

    题意:给定一个01串,一个有效的n切割定义如下:一个横杠代表一次切割,第一条横杠前面的01串不算,最后一条横杠后面的01串不算,将两个横杠中的01串转化成十进制数字,假设这些数字的最大值是MAX且这些 ...

  4. cf 757C. Felicity is Coming!

    这个题还是比较劲的(题意太神了),才知道vector还可以==和排序,扒题解大法好!! #include<bits/stdc++.h> #define lowbit(x) x&(- ...

  5. Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed

    题目连接:http://codeforces.com/contest/757/problem/D D. Felicity's Big Secret Revealed time limit per te ...

  6. Codeforces 757 D. Felicity's Big Secret Revealed 状压DP

    D. Felicity's Big Secret Revealed   The gym leaders were fascinated by the evolutions which took pla ...

  7. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  8. Codeforces Round #391 C. Felicity is Coming!

    题目链接 http://codeforces.com/contest/757/problem/C 题意:给你n组数范围在1-m,可进行变换f(x)=y,就是将所有的x全变成y,最后 要满足变化后每组数 ...

  9. Codeforces 757 C Felicity is Coming!

    题目大意:有n个训练营,m种宠物,每个训练营里里面有gi 个宠物,现在每只宠物都要完成一次进化,种类 相同的宠物进化之后,种类还是相同,种类不同的宠物不能进化成相同种类,且要求所有宠物进化之后,每个 ...

随机推荐

  1. multi role

    mesos 1.2.0实验性的支持了一个框架多个role. message FrameworkInfo { ... // Roles are the entities to which allocat ...

  2. mongodb 副本集部署

    1.安装三节点linux环境:196.168.1.111,196.168.1.112,192.168.1.113(三节点可彼此ping通) 2.三节点安装mongodb,参考https://blog. ...

  3. unittest测试

    标签(空格分隔): unittest unittest介绍: python里面也有单元测试框架-unittest,相当于是一个python版的junit. 一.unittest简介 1.先导入unit ...

  4. python学习day9 字符编码和文件处理

    1.字符编码 x='上' #unicode的二进制--------->编码-------->gbk格式的二进制 res=x.encode('gbk') #bytes 字节类型 print( ...

  5. 七 shelve模块

    shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型 import shelve f=shelve.o ...

  6. VM 端口映射问题

    环境: 宿主机:WIN 10 --192.168.9.87 虚拟机:CentOS ---192.168.255.129 联通模式:NAT模式 一.VM做端口映射 1.为了方便管理,设置虚拟机为静态IP ...

  7. python中matplotlib所绘制的图包含了很多的对象

    上图中的top=‘off’意思是说顶部的grid lines 看不见. 去除frame,意思就是将这个矩形给去除掉,spine意思是脊柱 bars = plt.bar(pos, popularity, ...

  8. Python+Selenium学习--浏览器设置

    场景 设置浏览器窗口的大小有下面两个比较常见的用途: 在统一的浏览器大小下运行用例,可以比较容易的跟一些基于图像比对的工具进行结合,提升测试的灵活性及普遍适用性.比如可以跟sikuli结合,使用sik ...

  9. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  10. 对arm裸板调试的理解

    由于arm芯片一般都包含的由jtag调试这项功能,cpu向外部发出信号时,一般都要同jtag发送出去,它就像一个路口的交警一样,能够控制车辆的运行,当然在arm中指的是cpu发出的数据和地址,我们在调 ...