HDU 5399(Too Simple-判定映射)
2015-08-24 19:39
330 查看
Too Simple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1035 Accepted Submission(s): 353
[align=left]Problem Description[/align]
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).
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each test case print the answer modulo
109+7.
[align=left]Sample Input[/align]
3 3 1 2 3 -1 3 2 1
[align=left]Sample Output[/align]
1 HintThe order in the function series is determined. What she can do is to assign the values to the unknown functions.
[align=left]Author[/align]
xudyh
[align=left]Source[/align]
2015 Multi-University Training Contest 9
[align=left]Recommend[/align]
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; }
相关文章推荐
- linux中文件描述符fd和文件指针flip的理解
- Java模拟公司置办货物系统(一)
- OutMan——Objective-C中分类、延展、非正式协议和协议
- 二叉树前序、中序、后序遍历相互求法
- Unix/Linux的内存管理
- 在macbook air配置android开发环境[eclipse篇]
- MFC自绘-WzdImage图像类
- Python自然语言处理学习笔记之信息提取步骤&分块(chunking)
- Java ArrayList中存放引用数据类型的问题
- hdu 4135,数学-容斥
- Libgdx 之 饱和度与色相的渲染
- Linux系统C语言操作环境变量的函数
- 使用netbeans工具查看JVM源码(上)
- 每天进步一点点——Linux中的文件描述符与打开文件之间的关系
- Linux系统C程序员的环境变量和环境表
- [转]svn提交自动同步到web服务器
- Docker 面临的安全隐患,我们该如何应对
- 手动修改magento域名
- Android读取assets下的文件
- Linux安装tomcat项目容器