记录一个菜逼的成长。。
题目大意:
有n家场馆,m种宠物小精灵。每个场馆有g[i]个小精灵,每种小精灵可以进化。进化规则f(x) = y。类型为x的可以进化为y。每个场馆要保证进化前后,每种类型的宠物小精灵数不变。问有几种方案。
标程简直不要太sao。。
数组a[i]的元素表示拥有类型的为i的宠物小精灵的场馆编号
然后用对二维类型的vector排序,排序规则同字符串排序。
然后统计场馆共同拥有的小精灵数,答案便是排列组合,乘上阶乘。
PS:没用过二维的vector排序,顺便记下。而且每个子数组还可以使用==运算,等同字符串相等规则。可以判断集合是否相等。
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long LL;
const int MOD = 1e9+7;
const int maxn = 1000000 + 10;
vector<int>a[maxn];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)){
for( int i = 1; i <= n; i++ ){
int cnt;
scanf("%d",&cnt);
while(cnt--){
int x;
scanf("%d",&x);
a[x].pb(i);
}
}
sort(a+1,a+1+m);
int ans = 1,t = 1;
for( int i = 2; i <= m; i++ ){
//统计有几个小精灵是一个或多个场馆共有的。
if(a[i] == a[i-1]){
t++;
ans = (LL)ans * t % MOD;//仔细看,其实是阶乘。
}
else {
t = 1;
}
}
printf("%d\n",ans);
}
return 0;
}