Codeforces 521A DNA Alignment Law
Question:
Given a string of n s.
Construct a string t with a length of n. So that the p (s, t) value is the largest, ask how many different t
H (s, t) = number of identical letters in the corresponding position
P (
AGC, Bytes,
CGT) Bytes = bytes
H(
AGC, Bytes,
CGT) Accept + accept
H(
AGC, Bytes,
GTC) Accept + accept
H(
AGC, Bytes,
TCG) Accept + accept
H(
GCA, Bytes,
CGT) Accept + accept
H(
GCA, Bytes,
GTC) Accept + accept
H(
GCA, Bytes,
TCG) Accept + accept
H(
CAG, Bytes,
CGT) Accept + accept
H(
CAG, Bytes,
GTC) Accept + accept
H(
CAG, Bytes,
TCG) Bytes = bytes 1 worker + WORKER 1 worker + worker 0 worker + worker 0 worker + WORKER 1 worker + WORKER 1 worker + WORKER 1 worker + worker 0 worker + WORKER 1 worker = worker 6 Ideas:
First, we construct a Letter of t, so that the letter and any letter of s will match at any two locations, and the corresponding times are n times. Therefore, the contribution of the constructed letter to the answer is Num [this_Letter] * n.
If A is entered in t, the value of p (s, t) is increased (the number of letters A in s) * n
To maximize p, the number of letters that can be entered in t must be the one with the largest number of letters in s.
The maximum number of letters in s and the number of letters that can be entered at each position in t.
#include
#include
#include 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, ans); return 0;}