Codeforces 521A DNA Alignment Law

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.