2017 Multi-University Training Contest
来源:互联网 发布:淘宝联盟能用电脑吗 编辑:程序博客网 时间:2024/04/30 23:07
欢迎参加——2017"百度之星"程序设计大赛
欢迎参加——2017“云上贵州”创新大赛 !
欢迎参加——2017“云上贵州”创新大赛 !
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1289 Accepted Submission(s): 591
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 functionf 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 functionsf 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 from0 to n−1 mapped into different integers in these two functions.
The answer may be too large, so please output it in modulo109+7 .
Define that the domain of function
Please calculate the quantity of different functions
Two functions are different if and only if there exists at least one integer from
The answer may be too large, so please output it in modulo
Input
The input contains multiple test cases.
For each case:
The first line contains two numbersn, m .(1≤n≤100000,1≤m≤100000)
The second line containsn numbers, ranged from 0 to n−1 , the i -th number of which represents ai−1 .
The third line containsm numbers, ranged from 0 to m−1 , the i -th number of which represents bi−1 .
It is guaranteed that∑n≤106, ∑m≤106 .
For each case:
The first line contains two numbers
The second line contains
The third line contains
It is guaranteed that
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[]的排列确定出f[i]的递推关系,构成几个递推环,b[]的排列构成答案环,如果b[]中的环长度能作为a[]环的因子,那么b[]环作为结果代入,就没有矛盾
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<algorithm>using namespace std;const long long MOD= 1e9+7;int n,m;int a[111111],b[111111];int f[111111];vector<int>Va,Vb;int ncase=0;int main(){ while(scanf("%d%d",&n,&m)==2) { Va.clear();Vb.clear(); for(int i=0;i<n;i++)scanf("%d",&a[i]); for(int i=0;i<m;i++)scanf("%d",&b[i]); memset(f,-1,sizeof(f)); for(int i=0;i<n;i++) { if(f[a[i]]==-1) { //f[a[i]]=0; int cnt=0; int k=a[i]; while(f[a[k]]==-1) { f[a[k]]=0; k=a[k]; cnt++; } if(cnt){Va.push_back(cnt);} } } //for(int i=0;i<Va.size();i++)cout<<Va[i]<<" "; memset(f,-1,sizeof(f)); for(int i=0;i<m;i++) { if(f[b[i]]==-1) { //f[a[i]]=0; int cnt=0; int k=b[i]; while(f[b[k]]==-1) { f[b[k]]=0; k=b[k]; cnt++; } if(cnt){Vb.push_back(cnt);} } } sort(Va.begin(),Va.end()); sort(Vb.begin(),Vb.end()); int lena=Va.size(); int lenb=Vb.size(); long long ans=1; int flag=0; for(int i=0;i<lena;i++) { long long mul=0; for(int j=0;j<lenb;j++) { if(Va[i]<Vb[j])break; if(Va[i]%Vb[j]==0){mul+=Vb[j];} } if(mul){flag++;ans=ans*mul%MOD;} else {ans=0;break;} } //if(flag<lena)ans=0; printf("Case #%d: %lld\n",++ncase,ans); } return 0;}
阅读全文
1 0
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- #2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- hibernate注解总结
- adb 被占用
- 第11章-使用对象-关系映射持久化数据
- 7.24-7.26 JLL实习日志-ajax+RestfulApi+Django-未完改进
- Properties的简介及使用
- 2017 Multi-University Training Contest
- 天价床垫有奇效?老人表示不信
- 微信小程序开发(5)-新闻页面制作之banner
- nodeJS之事件events
- Leetcode 第四章 栈和队列 --4.1栈--4.1.1Valid Parentheses--2017-7-27
- Linux文件属性
- DNS解析过程详解
- windows7下配置GO语言开发环境 Ide开发编辑器推荐Gogland
- mysql 5.7.19 免安装版的一些坑