【CodeForces - 520C】DNA Alignment (快速幂,思维)
題干:
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
1 COutput
1Input
2 AGOutput
4Input
3 TTTOutput
1Note
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
?
解題報(bào)告:
? ? 直接看哪個(gè)字母出現(xiàn)的次數(shù)最多就行了,注意有可能很多字母出現(xiàn)的次數(shù)一樣多,所以掃兩遍就做完了。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; char s[MAX]; int bk[20]; ll mod = 1e9+7; ll qpow(ll a,ll k) {ll res = 1;while(k) {if(k&1) res = (res*a)%mod;k>>=1;a=(a*a)%mod; }return res; } int main() {ll n;cin>>n;cin>>(s+1);int len = strlen(s+1);for(int i = 1; i<=len; i++) {if(s[i] == 'A') bk[1]++;if(s[i] == 'C') bk[2]++;if(s[i] == 'G') bk[3]++;if(s[i] == 'T') bk[4]++;}int maxx = *max_element(bk+1,bk+5);ll cur = 0;for(int i = 1; i<=4; i++) {if(bk[i] == maxx) cur++;}printf("%lld\n",qpow(cur,n));return 0 ;}?
總結(jié)
以上是生活随笔為你收集整理的【CodeForces - 520C】DNA Alignment (快速幂,思维)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 信用卡申请后多久拿到卡 不同的申请途径略
- 下一篇: 贾跃亭被开除之后 法拉第未来又地震了!