HDU 5399 Too Simple(数学 + 找规律)——2015 Multi-University Training Contest 9
2016-09-01 18:59
375 查看
传送门
Total Submission(s): 1673 Accepted Submission(s): 547
[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]
[align=left]Sample Output[/align]
[align=left]Author[/align] xudyh
[align=left]Source[/align]
题目大意:
这个题目的意思是很重要的,如果一旦读错了那这个题目就可以宣布不用做啦,刚开始我们就是读错题了,所以就…,后来通过上网看一下题解结果发现题目读错了。。。
题目的意思是:现在有 m 个 {1,2...n} → {1,2...,n} 的映射,其中有的映射是已经知道的,还有一些是未知的记作 −1 ,求对任意
i∈{1,2,...,n},f1(f2(...(fm(i)))=i 的方案总数。
解题思路;
其实这个题目经过观察之后就会发现,基本上方案数只与 −1 的个数有关系,因为当 m−1 个方程确定完之后,剩下的一个方程肯定就是确定的了,
也就是说假设 −1 的个数是 cnt 那么答案就是 (N!)cnt−1,然后特判一下,因为这个函数必须是 1−n 的,如果不是这样的就是直接输出 0,
当 cnt = 0 的时候需要特判一下,f1(f2(...(fm(i)))=i,从内到外一次判断一下就行了。
Too Simple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1673 Accepted Submission(s): 547
[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]
题目大意:
这个题目的意思是很重要的,如果一旦读错了那这个题目就可以宣布不用做啦,刚开始我们就是读错题了,所以就…,后来通过上网看一下题解结果发现题目读错了。。。
题目的意思是:现在有 m 个 {1,2...n} → {1,2...,n} 的映射,其中有的映射是已经知道的,还有一些是未知的记作 −1 ,求对任意
i∈{1,2,...,n},f1(f2(...(fm(i)))=i 的方案总数。
解题思路;
其实这个题目经过观察之后就会发现,基本上方案数只与 −1 的个数有关系,因为当 m−1 个方程确定完之后,剩下的一个方程肯定就是确定的了,
也就是说假设 −1 的个数是 cnt 那么答案就是 (N!)cnt−1,然后特判一下,因为这个函数必须是 1−n 的,如果不是这样的就是直接输出 0,
当 cnt = 0 的时候需要特判一下,f1(f2(...(fm(i)))=i,从内到外一次判断一下就行了。
/** 2016 - 09 - 01 晚上 Author: ITAK Motto: 今日的我要超越昨日的我,明日的我要胜过今日的我, 以创作出更好的代码为目标,不断地超越自己。 **/ #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <algorithm> #include <set> using namespace std; typedef long long LL; typedef unsigned long long ULL; const LL INF = 1e9+5; const int MAXN = 1e2+5; const LL MOD = 1e9+7; const double eps = 1e-7; const double PI = acos(-1); using namespace std; LL Scan_LL()///输入外挂 { LL res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } void Out(LL a)///输出外挂 { if(a>9) Out(a/10); putchar(a%10+'0'); } LL fac[MAXN]; void Init() { fac[0] = 1; fac[1] = 1; for(LL i=2; i<MAXN; i++) fac[i] = (fac[i-1]*i)%MOD; } LL quick_mod(LL a, LL b) { LL ans = 1; while(b) { if(b & 1) ans = (ans*a)%MOD; b>>=1; a = (a*a)%MOD; } return ans; } int a[MAXN][MAXN]; int vis[MAXN], ans[MAXN]; int main() { Init(); int n, m; while(cin>>n>>m) { LL cnt = 0; for(int i=1; i<=m; i++) { cin>>a[i][1]; if(a[i][1] == -1) { cnt++; continue; } for(int j=2; j<=n; j++) cin>>a[i][j]; } for(int i=1; i<=m; i++) { memset(vis, 0, sizeof(vis)); if(a[i][1] == -1) continue; for(int j=1; j<=n; j++) vis[a[i][j]] = 1; for(int i=1; i<=n; i++) if(!vis[i]) { puts("0"); goto endW; } } if(cnt == 0)///没有 -1 的时候 { for(int i=1; i<=n; i++) ans[i] = i; for(int i=m; i>0; i--) for(int j=1; j<=n; j++) ans[j] = a[i][ans[j]]; for(int i=1; i<=n; i++) { if(ans[i] != i) { puts("0"); goto endW; } } puts("1"); } else { LL ret = fac ; ret = quick_mod(ret, cnt-1); cout<<ret<<endl; } endW:; } return 0; }
相关文章推荐
- hdu 5389 Zero Escape DP+数学规律 给出证明 2015 Multi-University Training Contest 8
- HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3
- HDU 5288 OO’s Sequence(数学)——2015 Multi-University Training Contest 1
- 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】
- HDU 5351 MZL's Border(大数 + 找规律)——2015 Multi-University Training Contest 5
- hdu 5308 I Wanna Become A 24-Point Master(2015 Multi-University Training Contest 2)
- 2015多校联合训练赛 hdu 5305 Friends 2015 Multi-University Training Contest 2 枚举+剪枝
- [ 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 模拟题
- Hdu 5305 Friends 2015 Multi-University Training Contest 2
- hdu 5294 Tricks Device 2015 Multi-University Training Contest 1 isap + dijkstra
- Hdu 5302 Connect the Graph 2015 Multi-University Training Contest 2
- hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2
- 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题
- hdu 5299 Circles Game 2015 Multi-University Training Contest 1 计算几何+博弈SG函数 圆的扫描线
- hdu 5289 OO’s Sequence 2015 Multi-University Training Contest 1
- hdu 5307 He is Flying 2015 Multi-University Training Contest 2 快速傅里叶变换
- 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题
- hdu 5289 Assignment(2015 Multi-University Training Contest 1)
- hdu 4365 Palindrome graph (规律题 + 快速幂取模 2012 Multi-University Training Contest 7 )
- HDU 5305 Friends 2015 Multi-University Training Contest 2 1006