C. DNA Alignment 数学公式推导 Codeforces Round #295 (Div. 2)

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 stringssandthave the same lengthn, then the functionh(s,t)is defined as the number of positions in which the respective symbols ofsandtarethe same. Functionh(s,t)can be used to define the function of Vasya distanceρ(s,t):

whereis obtained from strings, by applying left circular shiftitimes. 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 stringsof lengthnon the Internet. Now he wants to count how many stringstthere are such that the Vasya distance from the stringsattains maximum possible value. Formally speaking,tmust 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 integern(1≤n≤105).

The second line of the input contains a single string of lengthn, consisting of characters"ACGT".

Output

Print a single number— the answer modulo109+7.

Sample test(s)

input

1C

output

1

input

2AG

output

4

input

3TTT

output

1

Note

Please note that if for two distinct stringst1andt2valuesρ(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 stringstof 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

题意:给一个由A,T,C,G组成的字符串s,求使ρ(s,t)最大的t的个数。易知,t应该由字符串s中个数最多的字母组成(总数最多的字母只有一个的时候很好理解,如果有多个字母的个数相同,那么就可以将这些个数相同的字母看成一个字母,,这样是等价的),求出字母个数最多的种类数x,根据排列组合,答案就是x^n

代码:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 100005#define MAXN 2005#define mod 1000000007#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE(i,a,b) for(i = a; i <= b; i++)#define FRL(i,a,b) for(i = a; i < b; i++)#define mem(t, v) memset ((t) , v, sizeof(t))#define sf(n)scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pfprintf#define DBGpf("Hi\n")typedef long long ll;using namespace std;__int64 n;char str[maxn];__int64 num[30];__int64 pow_m(__int64 a,__int64 n){__int64 ret=1;__int64 tmp=a%mod;while (n){if (n&1) ret=(ret*tmp)%mod;tmp=tmp*tmp%mod;n>>=1;}return ret;}int main(){while (~scanf("%I64d",&n)){scanf("%s",str);mem(num,0);for (__int64 i=0;i<n;i++)num[ str[i]-'A' ]++;__int64 maxx=0;for (__int64 i=0;i<26;i++)maxx=max(maxx,num[i]);__int64 m=0;for (__int64 i=0;i<26;i++)if (num[i]==maxx) m++;printf("%I64d\n",pow_m(m,n));}return 0;}

追寻爱情,然后发现,爱,从来就是一件千回百转的事。

C. DNA Alignment 数学公式推导 Codeforces Round #295 (Div. 2)

相关文章:

你感兴趣的文章:

标签云: