• Codeforces 757C. Felicity is Coming!


    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后进行比较。

    代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<map>
     7 #include<vector>
     8 #include<queue>
     9 using namespace std;
    10 const int MAXN=1e6+100,mod=1e9+7;
    11 vector<int>v[MAXN];
    12 int main()
    13 {
    14     int n,m;
    15     scanf("%d%d",&n,&m);
    16     for(int i=1; i<=n; i++)
    17     {
    18         int g;
    19         scanf("%d",&g);
    20         for(int j=1; j<=g; j++)
    21         {
    22             int x;
    23             scanf("%d",&x);
    24             v[x].push_back(i);
    25         }
    26     }
    27     sort(v+1,v+m+1);///涨姿势了!
    28     /*
    29     for(int i=1;i<=m;i++)
    30     {
    31         for(int j=0;j<v[i].size();j++)
    32             cout<<v[i][j]<<" ";
    33         cout<<endl;
    34     }
    35     */
    36     __int64 ans=1;
    37     int t=1;
    38     for(int i=2; i<=m; i++)
    39     {
    40         if(v[i]==v[i-1])
    41         {
    42             t++;
    43             ans=(ans*t)%mod;
    44         }
    45         else t=1;
    46     }
    47     cout<<ans<<endl;
    48     return 0;
    49 }
    用sort对vector数组排序

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

    I am a slow walker,but I never walk backwards.
  • 相关阅读:
    PHP实现微信开发中提现功能(企业付款到用户零钱)
    微信开发企业支付到银行卡PHP
    详解PHP实现定时任务的五种方法
    PHP实现执行定时任务的几种思路详解
    Laravel 去掉访问后面的 “public”
    laravel 中数据库查询结果自动转数组
    怎样才能去掉图片上的二维码
    用PS修改PNG格式图标的颜色
    消除浏览器对input输入框的自动填充
    知网---压缩传感研究现状
  • 原文地址:https://www.cnblogs.com/GeekZRF/p/6285673.html
Copyright © 2020-2023  润新知