Topic Link: Click to open the link
Test instructions
A string s that is given a length of N.
Constructs a string t with a length of N. Makes the P (s,t) value the largest, asking how many different t
H (s,t) = The same number of letters in the corresponding position
ρ ("
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 Ideas:
First we construct a letter of T, then the letter and the letter s of any one of the letters in any two positions will be matched once, and the corresponding number of times have n times. So the construction of this letter to the answer contribution is num[this_letter] * n
If a is filled in T, then the value of P (s,t) increases (the number of a letters in s) *n
So in order for p to be the largest, the letters that can be filled in T must be the largest number of letters in S.
The number of letters in S is as many as possible, and how many letters can be filled in each position in T.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int max_n = 100007; Const long Long mod = 1000000007;long long Pow (long long x, long long N) { long long res = 1; while (n > 0) { if (N & 1) res = res * x% MoD; x = x * x% mod; n >>= 1; } return res;} Char Str[max_n];int a[5], N;int main () { scanf ("%d%s", &n, str); for (int i = 0; str[i]; ++i) { if (str[i] = = ' A ') ++a[0]; else if (str[i] = = ' C ') ++a[1]; else if (str[i] = = ' G ') ++a[2]; else ++a[3]; } int up = 0; for (int i = 0; i < 4; ++i) up = max (up, A[i]); int cnt = 0; for (int i = 0; i < 4; ++i) if (a[i] = = up) ++cnt; Long Long ans = Pow (CNT, n); printf ("%i64d\n", ans); return 0;}
Codeforces 521A DNA Alignment Law