Codeforces 521A DNA Alignment【贪心+思维】

来源:互联网 发布:mysql怎么创建索引 编辑:程序博客网 时间:2024/05/24 06:19

A. 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 functionh(s, t) is defined as the number of positions in which the respective symbols ofs and t arethe same. Function h(s, t) can be used to define the function of Vasya distanceρ(s, t):

where is obtained from strings, 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 modulo109 + 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.

Examples
Input
1C
Output
1
Input
2AG
Output
4
Input
3TTT
Output
1
Note

Please note that if for two distinct strings t1 andt2 values ρ(s, t1) и ρ(s, t2) are maximum among all possiblet, 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 stringst 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


题目大意:


让你构造一个字符串,其中只包含ACGT四种元素,使得其p的值最大,p的值按照题干图示求得。


思路:


首先我们确定,要使得p的值尽可能的大 ,那么我们一定必须要让原字符串出现次数最多的字符出现次数最多。

那么:

①如果只有一种字符出现次数最多,例如:ACCCC,那么我们构造出来的串:CCCCC一定是分值最高的串。

②如果有多种字符出现次数最多且出现次数相同,那么我们对应N个位子随意分配这几种出现次数相同的字符即可,那么答案就是:

出现次数最多的字符^N。


Ac代码:


#include<stdio.h>#include<iostream>#include<string.h>using namespace std;#define MOD 1000000007#define ll __int64ll vis[5];ll cont[5];char a[100006];int main(){    int n;    while(~scanf("%d",&n))    {        scanf("%s",a);        memset(cont,0,sizeof(cont));        memset(vis,0,sizeof(vis));        for(int i=0;i<n;i++)        {            if(a[i]=='A')vis[0]++;            if(a[i]=='C')vis[1]++;            if(a[i]=='T')vis[2]++;            if(a[i]=='G')vis[3]++;        }        for(int i=0;i<4;i++)        {            if(vis[i]==0)continue;            for(int j=0;j<4;j++)            {                if(vis[i]==vis[j])cont[i]++;            }        }        ll maxn=0;        ll contz=0;        for(int i=0;i<4;i++)        {            if(vis[i]>maxn)            {                maxn=vis[i];                contz=cont[i];            }        }        ll output=1;        for(int i=0;i<n;i++)        {            output*=contz;            output%=MOD;        }        printf("%I64d\n",output);    }}





0 0
原创粉丝点击