codefrcces 520c 思维

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 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.

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


题意: 题意很长很恶心  ,  就是给你一个字符串  由  ACGT  组成    你要找出一个串  和他的循环匹配最大

(我自己起的名字)

这个意思就是上边 的  那个公式。 使得 公式的结果最大,  问你这样的字符串最多有多少。

思路:  不能说是一个傻逼题  吧 ,但是仔细一想其实还是很水    注意你要找的串 是和原串  进行循环着匹配 

,看每一位是否相同那么  你要找的串的每一位都会和原串的每一位  匹配到 , 那么你就只需要找出原串

中哪个  字符 出现的次数最多。 这样的话然后  统计最多次数的  字符个数。   然后我们考虑我们要找的串  

对于我们要找的串 中的每一位,我们都可以放这种出现次数最多的字符,那么最后形成的串

 一定是和原串的匹配 最大。 所以就是  k  的n  次方了。(k  是原串中出现次数最多的字符的个数 )

 

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

string s;
map<char,int >mp;
int n;

const int mod=1e9+7;

ll quick_pow(ll a,ll k)
{
	ll ans=1;
	while(k)
	{
		if(k&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		k>>=1;
	}
	
	return ans%mod;
}

int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		mp[s[i]]++;
	}
	
	int maxx=-1;
	maxx=max(maxx,mp['A']);
	maxx=max(maxx,mp['C']);
	maxx=max(maxx,mp['G']);
	maxx=max(maxx,mp['T']);
	
	ll k=0;
	if(mp['A']==maxx) k++;
	if(mp['C']==maxx) k++;
	if(mp['G']==maxx) k++;
	if(mp['T']==maxx) k++;
	
	ll ans=quick_pow(k,n);
	
	cout<<ans<<endl;
	return 0; 
	
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值