企业如何利用HarmonyOS开发工具提升小程序开发效率与合规性
540
2022-11-09
HDU 6038 Function (数学)
Description
You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1.Define that the domain of function f is the set of integers from 0 to n−1, and the range of it is the set of integers from 0 to m−1.Please calculate the quantity of different functions f satisfying that f(i)=bf(ai) for each i from 0 to n−1.Two functions are different if and only if there exists at least one integer from 0 to n−1 mapped into different integers in these two functions.The answer may be too large, so please output it in modulo 10^9+7.
Input
The input contains multiple test cases.For each case:The first line contains two numbers n, m. (1≤n≤100000,1≤m≤100000)The second line contains n numbers, ranged from 0 to n−1, the i-th number of which represents ai−1.The third line contains m numbers, ranged from 0 to m−1, the i-th number of which represents bi−1.It is guaranteed that ∑n≤106, ∑m≤106.
Output
For each test case, output “Case #x: y” in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
3 21 0 20 13 42 0 10 2 3 1
Sample Output
Case #1: 4Case #2: 4
题意
给出两个序列 a 和 b ,求满足 f(i)=bf(ai)
思路
根据样例 1 我们可以得到:
f(0)=bf(1)
f(1)=bf(0)
f(2)=bf(2)
代换以后有 f(0)=bf(1)=bbf(0) , f(1)=bf(0)=bbf(1)
考虑置换 a 的一个循环节,长度为 l ,那么有 f(i)=bf(ai)=bbf(aai)=b⋯bf(i)l times b
于是 f(i) 的值在置换 b 中所在的循环节的长度必须为 l
而如果 f(i) 的值确定下来了,这个循环节的另外 l−1
因此满足条件的函数个数就是 ∏ki=1∑j|lij⋅calj ,其中 k 是置换 a 中循环节的个数, li 表示置换 a 中第 i 个循环节的长度, calj 表示置换 b 中长度为 j
AC 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~