Codeforces 521A DNA Alignment Law

Source: Internet
Author: User

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;}
  
 


 

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.