# Codeforces Round #295 (Div. 2) C. DNA Alignment ACM解题报告（math）

What is ρ(s, t) equal to? For every character of s and every character of t there is a unique cyclic shift of t that superposes these characters (indeed, after 0, ...n - 1 shifts the character in t occupies different positions, and one of them matches the one of the character of s); therefore, there exist n cyclic shifts of s and t that superpose these characters (the situation is symmetrical for every position of the character of s). It follows that the input in ρ from a single character ti is equal to n × (the number of characters in s equal to ti). Therefore, ρ(s, t) is maximal when every character of t occurs the maximal possible number of times in s. Simply count the number of occurences for every type of characters; the answer is Kn, where K is the number of character types that occur in s most frequently. This is an O(n) solution.

<span style="font-size:10px;">#include<bits/stdc++.h>>//新的头文件好炫酷
using namespace std;
#define MAX 20000+5
typedef long long LL;
const double pi=3.141592653589793;
const int INF=1e8;
const double inf=1e20;
const double eps=1e-6;
const int mod=1000000007;
int main(){
int n,a[30];
string s;
cin>>n>>s;
a['A'-'A']=0;
a['C'-'A']=1;
a['G'-'A']=2;
a['T'-'A']=3;
int b[4]={0,0,0,0};
int len=s.size();
for(int i=0;i<len;i++) b[a[s[i]-'A']]++;
int maxn=max(max(b[0],b[1]),max(b[2],b[3]));
int size=0;
for(int i=0;i<4;i++) if(b[i]==maxn) size++;
LL ans=1;
for(int i=0;i<len;i++) ans=(ans*size)%mod;
printf("%I64d\n",ans);
return 0;
}
</span>

• 写评论