DNA Alignment
来源:互联网 发布:淘宝下拉框软件 编辑:程序博客网 时间:2024/06/13 06:52
DNA Alignment
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.
Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s, t) can be used to define the function of Vasya distance ρ(s, t):
Vasya found a string s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: .
Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109 + 7.
The first line of the input contains a single integer n (1 ≤ n ≤ 105).
The second line of the input contains a single string of length n, consisting of characters "ACGT".
Print a single number — the answer modulo 109 + 7.
1C
1
2AG
4
3TTT
1
Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.
In the first sample, there is ρ("C", "C") = 1, for the remaining strings t of length 1 the value of ρ(s, t) is 0.
In the second sample, ρ("AG", "AG") = ρ("AG", "GA") = ρ("AG", "AA") = ρ("AG", "GG") = 4.
In the third sample, ρ("TTT", "TTT") = 27
Code:
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>#define mod 1000000007#define ll long long using namespace std;int ans,mx,n,num[30];char ch[100005];ll power(ll a,ll b){ ll ans=1;a%=mod; for(ll i=b;i;i>>=1,a=a*a%mod) if(i&1)ans=ans*a%mod; return ans;}int main(){ scanf("%d",&n); scanf("%s",ch+1); for(int i=1;i<=n;i++) { num[ch[i]-'A'+1]++; mx=max(mx,num[ch[i]-'A'+1]); } for(int i=1;i<=26;i++) if(num[i]==mx)ans++; printf("%I64d\n",power(ans,n)); return 0;}
- DNA Alignment
- 520C DNA Alignment
- CodeForces 520C DNA Alignment
- CodeForces 520C DNA Alignment
- C. DNA Alignment(Codeforces Round #295(div2))
- Codeforces Round #295 C. DNA Alignment
- Codeforces 521A - DNA Alignment (思维)
- #295 (div.2) C.DNA Alignment
- 【Codeforces】 CF 520C DNA Alignment
- Codeforces 520C. DNA Alignment 找规律
- Codeforces 521A DNA Alignment 规律
- 520C DNA Alignment (快速幂)
- Codefoces 520C DNA Alignment 乱搞题
- Codeforces 521A DNA Alignment【贪心+思维】
- POJ 2520 DNA Sequence Alignment 笔记
- C. DNA Alignment 数学公式推导 Codeforces Round #295 (Div. 2)
- Codeforces Round #295 (Div. 2) C. DNA Alignment(数学)
- Codeforces Round #295 (Div. 2) C. DNA Alignment
- 机器学习一(逻辑回归)
- hdu 1878 欧拉回路
- Spring MVC框架原理(待补充)
- pycharm 提示 No module named 'XXX'
- Android开发之版本检查更新
- DNA Alignment
- 【HTML】HTML学习笔记
- Ubuntu 不在sudoers文件中
- 多个list合并去重
- 记录几个盲点 20170922
- 定义平面中的一个Circle类, 1编写一个无参数构造函数, 2编写一个有参的构造函数 3在主函数中调用无参构造函数生成圆的实例c1,调用有参构造函数生成圆的实例c2,调用实例方法判断c1和c2是否重
- JAVA课程1用NPP写HW
- 二叉树的基本操作(插入、查找)
- class Introduction to Databases in Python