Codeforces 520C. DNA Alignment 找規律,codeforces520c

來源:互聯網
上載者:User

Codeforces 520C. DNA Alignment 找規律,codeforces520c


等價於一個不左移一個左移然後結果乘上n,也就是第二個串的每個字元都會和第一個串的某個字元配對一次,所以選擇出現次數最多的字元更好.

如果有多個字元出現次數都是最多的,結果為最多的字元種類數的n次方

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 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
1C
output
1
input
2AG
output
4
input
3TTT
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



/* ***********************************************Author        :CKbossCreated Time  :2015年03月02日 星期一 21時54分48秒File Name     :C.cpp************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>using namespace std;typedef long long int LL;const int maxn=100100;const int mod=1e9+7;int n,A,G,C,T;char dna[maxn];int main(){    //freopen("in.txt","r",stdin);    //freopen("out.txt","w",stdout);scanf("%d",&n);scanf("%s",dna);for(int i=0;i<n;i++){if(dna[i]=='A') A++;if(dna[i]=='G') G++;if(dna[i]=='C') C++;if(dna[i]=='T') T++;}int mx=max(max(A,G),max(C,T));int nt=0;if(A==mx) nt++; if(G==mx) nt++;  if(C==mx) nt++; if(T==mx) nt++;LL ans=1LL;for(int i=0;i<n;i++){ans=(ans*nt)%mod;}cout<<ans%mod<<endl;        return 0;}




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.