博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #295 (Div. 2)C - DNA Alignment 数学题
阅读量:7120 次
发布时间:2019-06-28

本文共 2684 字,大约阅读时间需要 8 分钟。

C. DNA Alignment
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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):

where
is obtained from string
s, by applying left circular shift i times. For example,
ρ("AGC", "CGT") = 
h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") + 
h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") + 
h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") = 
1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6

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.

Input

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".

Output

Print a single number — the answer modulo 109 + 7.

Sample test(s)
Input
1 C
Output
1
Input
2 AG
Output
4
Input
3 TTT
Output
1
Note

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

int idx(char a){    if(a=='A')        return 0;    if(a=='G')        return 1;    if(a=='C')        return 2;    if(a=='T')        return 3;}int flag[4];int powmod(int a,int b) {    LL ans = 1,x = a;    while (b) {        if (b & 1) ans = ans * x % MOD;        x = x * x % MOD;        b >>= 1;    }    return ans;}int main(){    int n;    cin>>n;    string s;    cin>>s;    REP(i,s.size())        flag[idx(s[i])]++;    int max_num=0;    int max_kiss=0;    REP(i,4)        max_num=max(max_num,flag[i]);    REP(i,4)    {        if(flag[i]==max_num)            max_kiss++;    }    cout<
<

 

转载地址:http://brnel.baihongyu.com/

你可能感兴趣的文章
Linux系统日志详解
查看>>
Linux笔记(shell特殊符号,sort排序,wc统计,uniq去重,tee,tr,split)
查看>>
11.15PMP试题每日一题
查看>>
华为模拟器如何实现不同Vlan不同网段之间的互通
查看>>
PHP 实现Session入库/存入redis
查看>>
手机锁屏密码忘记了怎么办,清除锁屏的办法
查看>>
BVS烟火识别输油站烟火检测应用
查看>>
使用Apache Ignite构建C++版本的分布式应用
查看>>
数据库基本概念
查看>>
恢复后缀ETH勒索病毒解密方法 恢复sql文件.com].ETH
查看>>
找到dht网络的节点了
查看>>
国内整C多IP服务器怎么搭建代理IP,又怎么区分代理IP呢
查看>>
人工智能+教育的应用——教育的安全
查看>>
一种面包屑导航
查看>>
shell脚本练习
查看>>
pdf页眉页脚设置步骤
查看>>
MySQL常用命令
查看>>
js如何保证iframe里的内容,显示在父窗口
查看>>
加速你的企业数字化转型,首先做到这一步!
查看>>
Mysql复制架构
查看>>