hdu 5399 Too Simple 2015多校聯合訓練賽#9 類比

來源:互聯網
上載者:User

Too Simple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 797    Accepted Submission(s): 268


Problem Description Rhason Cheung had a simple problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.

Teacher Mai has  m functions  f1,f2,⋯,fm:{1,2,⋯,n}→{1,2,⋯,n}(that means for all  x∈{1,2,⋯,n},f(x)∈{1,2,⋯,n}). But Rhason only knows some of these functions, and others are unknown.

She wants to know how many different function series  f1,f2,⋯,fm there are that for every  i(1≤i≤n), f1(f2(⋯fm(i)))=i. Two function series  f1,f2,⋯,fm and  g1,g2,⋯,gm are considered different if and only if there exist  i(1≤i≤m),j(1≤j≤n), fi(j)≠gi(j).
 
Input For each test case, the first lines contains two numbers  n,m(1≤n,m≤100).

The following are  m lines. In  i-th line, there is one number  −1 or  n space-separated numbers.

If there is only one number  −1, the function  fi is unknown. Otherwise the  j-th number in the  i-th line means  fi(j).
 
Output For each test case print the answer modulo  109+7.
 
Sample Input

 3 3 1 2 3 -1 3 2 1   

Sample Output
 1 Hint The order in the function series is determined. What she can do is to assign the values to the unknown functions.   

Author xudyh  
Source 2015 Multi-University Training Contest 9

如果有-1,且函數合法,那麼就有(N。)^(x-1),x是-1的個數

否則只需要判斷函數映射是否會x= f(f(f....f(x))即可

函數合法的條件是:y = f(x) y包含1到n的每個數字


#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>using namespace std;int f[101][101];#define ll long longint jie[101];int mod = 1000000007;int ans[101];int main(){    int n,m;    jie[0]  = 1;    for(int i =1; i <= 100;i++)        jie[i] =1ll*jie[i-1]*i%mod;    while(scanf("%d%d",&n,&m)!=EOF){        int res = 0;        for(int i = 0;i < m; i++){            scanf("%d",&f[i][1]);            if(f[i][1] == -1) {                res++;                continue;            }            for(int j = 2;j <= n; j++)                scanf("%d",&f[i][j]);        }        if(res == 0){            for(int i = 1;i <= n; i++)                ans[i] = i;            for(int i = m-1; i >= 0; i--)                for(int j = 1;j <= n; j++)                    ans[j] = f[i][ans[j]];            res = 1;            for(int i = 1;i <= n; i++)                if(ans[i] != i ) res = 0;            if(res)puts("1");            else puts("0");        }        else {            int flag = 1;            for(int i = 0;i < m && flag; i++){                if(f[i][1] == -1) continue;                memset(ans,0,sizeof(ans));                for(int j = 1;j <= n;j++)                    ans[f[i][j]] = 1;                for(int j = 1;j <= n;j++)                    if(ans[j] == 0)                        flag = 0;            }            if(flag == 0) puts("0");            else {                ll t = 1;                for(int i = 1;i < res; i++){                    t = t*jie[n]%mod;                }                cout<<t<<endl;            }        }    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.