A simple construct that you read the code to understand

Source: Internet
Author: User

Codeforces 520c

Train of thought: two strings, the first string does not move, you will find that each character of the second string will be a character pair with the first string, so when constructing it, the one with the most occurrences is chosen.

If the number of characters to assume the most occurrences of K, the first character has a k choice, the second has a k choice .... The nth character has a K-type choice,

RK (K,n);

#include <iostream>
using namespace Std;
#define M 1000000007;
int n;
Char a[100010];
int c[5];

//Two min fast exponentiation
  Long long rk (int n, int k)
 {
     Long Long res = 1;
     while (k) {
         if (K & 1)
              res *= N, res%= M;
         n *= N;
        n%= M;
         k >>= 1;
    }
     return res;
 }
 int Main ()
 {
     int i;
     Cin>>n>>a;

Iterate through a string to count the occurrences of each character
for (i = 1; I <= n; ++i)
{
if (a[i]== ' a ')
c[1]++;
else if (a[i]== ' G ')
c[2]++;
else if (a[i]== ' C ')
c[3]++;
Else
c[4]++;
}

Find out the number of occurrences of the most numerous occurrences of that character
int max = MAX (max (c[1], c[2]), Max (c[3], c[4]);
int m=0;

Get the type of the most numerous characters appearing
for (i = 1; I <= 4; ++i)
if (Max = = C[i])
m++;
Cout<<rk (M, N) <<endl;
}

A simple construct that you read the code to understand

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.