hdu 6038 Function【置换群进阶】
来源:互联网 发布:2017全国双创数据报告 编辑:程序博客网 时间:2024/06/08 00:29
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1389 Accepted Submission(s): 644
Problem 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 109+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 2
1 0 2
0 1
3 4
2 0 1
0 2 3 1
Sample Output
Case #1: 4
Case #2: 4
Source
2017 Multi-University Training Contest - Team 1
题意:
给定两个数列 a 和 b, 求有多少个 f 映射满足: f(i)=bf(ai);
思路:
写了好久,结果样例画错一个群QAQ。要满足这种映射,来回之间的转换,需要用到置换群的思想,那么就需要求群和循环节,但是本题题意显然并不需要每个元素的循环节,而是把同在一个群的元素整合成一个群,这个群的长度便是这个群的循环节。合并之后,就要A映射B,当B序列某个群的循环节大于A序列某个群的循环节时,映射后的f函数最后一项是错的。换句话说,只有当B序列某个置换群循环节是A的因子,才能满足条件,B的这个子群的循环节就是此时满足映射关系的个数;
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define max_n 100010const int mod=1e9+7;using namespace std;typedef long long LL;int a[max_n],b[max_n],A[max_n],B[max_n],vis[max_n];int getp(int a[],int A[],int n) //求置换群的个数以及每个群的循环节 { memset(vis,0,sizeof(vis)); int cnt=0; for(int i=0;i<n;i++) { int t=a[i],res=0;//编号是0~n-1,所以起始res=0 if(!vis[i]) { while(!vis[t]) { vis[t]=1; t=a[t]; res++; } A[cnt]=res; //每个群元素的个数也就是这个群的循环节 cnt++; //群的个数 } } return cnt;}int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF) { memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<m;i++) scanf("%d",&b[i]); int cnta=getp(a,A,n); int cntb=getp(b,B,m); LL ans=1; for(int i=0;i<cnta;i++) { LL res=0; for(int j=0;j<cntb;j++) { if(A[i]%B[j]==0)//当B序列是A序列的因子时,B序列长度就是方案数 res+=B[j]; } ans=(ans*res)%mod; } static int p=1; printf("Case #%d: %lld\n",p++,ans); } return 0;}
- hdu 6038 Function【置换群进阶】
- HDU 6038 Function 置换群
- HDU 6038 Function 【置换群】
- HDU 6038 Function(置换->循环节)
- HDU6038-Function(置换群)
- 2017 多校 Function(置换群
- hdu 4259 置换群
- HDU-置换群
- HDU 5495 置换群
- HDU 5495(置换群)
- hdu 置换群
- 【HDU】1439 Cipher 置换群
- hdu 5495 LCS 置换群
- 【HDU 1439】Cipher(置换群)
- hdu 4529 Double Dealing (置换群)
- HDU 4259 Double Dealing【简单群置换】
- HDU 5495 LCS (置换群)
- HDU 5495 LCS(置换群)
- cxf+webservice(java)
- 动态规划--装满背包的最小价值--hdu1114 Piggy-bank
- function(url)方法不能传例如url=“http://localhost:8081/orig/list” 这种路径的解决方案
- MyBatis 详解(一对一,一对多,多对多)
- 强连通算法--Tarjan
- hdu 6038 Function【置换群进阶】
- Linux pthread_cond_t 封装
- 如何把安全证书导入到java中的cacerts证书库
- postgresql从入门到菜鸟(三)
- androd自定义view实现圆显示进度和百分比的控件
- c#数据类型转换方法
- pyhton学习笔记之安装cx_Oracle模块那些事儿及操作oracle小实例
- iOS工程需要了解的排序算法
- 互联网时代,如何能保障用户的“数据隐私”?