HDU 5399(Too Simple-判定映射)
来源:互联网 发布:淘宝商城童装毛衣女孩 编辑:程序博客网 时间:2024/06/04 20:23
Too Simple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1035 Accepted Submission(s): 353
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 hasm 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 seriesf1,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) .
Teacher Mai has
She wants to know how many different function series
Input
For each test case, the first lines contains two numbersn,m(1≤n,m≤100) .
The following arem 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) .
The following are
If there is only one number
Output
For each test case print the answer modulo 109+7 .
Sample Input
3 31 2 3-13 2 1
Sample Output
1HintThe 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
Recommend
wange2014 | We have carefully selected several similar problems for you: 5421 5420 5419 5418 5417
已知函数有一个不是双射,必定无解
若所有函数均已知,直接判断
否则,只要有一个 -1, 那么必能构造出解
有k个-1,前k-1个随便排 ,最后那个就能推出 ans=(n!)^(k-1)
#include<bits/stdc++.h> using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (1000000007)#define MAXN (100+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int n,m;bool b[MAXN];int f[MAXN][MAXN];int g[MAXN];int main(){//freopen("D.in","r",stdin);while(cin>>n>>m) {int cnt=0; bool flag=0;For(i,m){MEM(b)int p;scanf("%d",&p);if (p==-1) { ++cnt;continue;}else f[i][1]=p;b[p]=1;Fork(j,2,n) {scanf("%d",&p);f[i][j]=p;if (!b[p]) b[p]=1; else flag=1;}}if (flag) {puts("0");continue;}if (!cnt) {For(i,n) g[i]=i;ForD(i,m) For(j,n) g[j]=f[i][g[j]];bool flag=0;For(i,n) if (g[i]^i) flag=1;if (flag) puts("0");else puts("1");continue;}if (cnt==1){puts("1");continue;}ll ans=1,p2=1;For(i,n) p2=mul(p2,i);For(i,cnt-1) ans=mul(p2,ans);cout<<ans<<endl;}return 0;}
0 0
- HDU 5399(Too Simple-判定映射)
- HDU 5399 Too Simple (区分映射与函数)()
- HDU 5399 Too Simple
- HDU 5399 Too Simple
- hdu 5399 Too Simple
- hdu 5399 Too Simple(计数)
- hdu 5399 Too Simple(思路题,函数)
- 【HDOJ 5399】Too Simple
- HDOJ 5399 Too Simple
- hdu5399 Too Simple(函数映射)
- 多校第九场 1004 hdu 5399 Too Simple(贪心)
- 2015多校第九场 HDU 5399 Too Simple
- too young too simple
- too young too simple
- too young too simple
- HDU 5399 Too Simple (2015年多校比赛第9场)
- hdu 5399 Too Simple 2015多校联合训练赛#9 模拟
- HDU 5399 Too Simple(数学 + 找规律)——2015 Multi-University Training Contest 9
- SDKD Summer Team Contest S
- UML——类图
- Libgdx 之 饱和度与色相的渲染
- HDOJ 2824 The Euler function(欧拉函数+打表法)
- Linux系统C程序员的环境变量和环境表
- HDU 5399(Too Simple-判定映射)
- 每天进步一点点——Linux中的文件描述符与打开文件之间的关系
- OL记载Arcgis Server切片
- Linux系统C语言操作环境变量的函数
- Round A APAC Test 2016 Problem A. Googol String
- HOJ 13415 Website Tour(强连通缩点+多重背包dp)
- Nginx从入门到精通
- hdu 4135,数学-容斥
- 关于更佳学术搜索及Android SDK更新问题