C. Derivation of the mathematical formula for DNA Alignment codeforces Round #295 (Div. 2)

Source: Internet
Author: User

C. DNA alignmenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 similar ity of cyclic sequences.

Let's assume that stringssandTHave the same lengthN, then the function H(s,? T)is defined as the number of positions in which the respective symbols ofsandTIsThe same. Function H(s,? T)Can is used to define the function of Vasya distanceρ (s,? ) T):

Where is obtained from string s, by applying left circular shift ITimes. 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

Vas Ya found a string  N  on the Internet. Now he wants to count how many Strings  s  attains maximum possible value. Formally speaking,  t  must satisfy the equation: .

Vasya could not try all possible strings to find a answer, so he needs your help. As the answer may very large, count the number of the such strings modulo 9? +?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 9? +?7.

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

Please note this if for distinct strings t1 and t2 Valuesρ (s,? ) T1)Иρ (s,? ) T2)is maximum among all possibleT, then both strings must is taken into account in the answer even if one of the them can is obtained by a circular shift of a Other 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


Test instructions: To a string s composed of a,t,c,g, to makeρ(s,t) The maximum number of T. It is easy to know that T should be composed of the most number of letters in the string s (the largest number of letters only one time very well understood, if there are multiple letters of the same number, then you can use the same number of letters as a letter, this is equivalent), the number of letters to find the most of the type of x, according to the combination of ^n

Code:

#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 RSO N 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, & AMP;B) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF printf#define DBG pf ("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. Derivation of the mathematical formula for DNA Alignment codeforces Round #295 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.