1 model (6) day1

Source: Internet
Author: User

Question 1:

Question:

A [I] of N is a single peak. if and only when an x exists, a [1] <A [2] <... <A [x]> A [x + 1]>...> A [n]. Try to calculate the total number of n single-peaks in mod 1234567. N <= 2 000 000 000

 

Problem solving process:

1. first of all, the so-called "peak" must be the number N, so according to the N position to discuss, we can find that the number of N in the I position is C (n-1, I-1 ); therefore, the total number of solutions is sum {C (n-1, 0... n-1 )};

According to the binary theorem sum {C (n-1, 0... N-1)} = (1 + 1) ^ (n-1) = 2 ^ (n-1); Use A Rapid power calculation.

 

Question 2:

Question:

There is a dot matrix of m rows and n columns, and two adjacent points can be connected. A vertical line takes one unit, and a horizontal line takes two units. Some vertices are connected. How many units are required to connect all vertices at least. M, n <= 1000

 

Problem solving process:

1. Since it is necessary to connect, we naturally think of the smallest spanning tree, but there will be a lot of edges, and the Kruskal algorithm uses (eloge) time sorting. It must have timed out.

2. for further consideration, there are only three edge values: 0, 1, and 2, the sequential number of edge sets can be obtained after 2 is stored, and then the traditional Kruskal.

 

Question 3:

N pairs are given, indicating that the letters X and Y must be adjacent (that is, "XY" or "Yx" must appear in the string) and the string with the smallest Lexicographic Order is obtained, the given n pairs are satisfied and the length is n + 1;

 

Problem solving process:

1. Virtualize a letter into a dot and describe the link to an edge. This question is actually an Euler's path.

2. Obtain the number CNT of the singularity. If it is not 0 or 2, no solution is output.

3. If CNT = 0, you can search for a small-coded letter. If CNT = 2, you must start from the singularity.

 

1 model (6) day1

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.