Algorithmic competition Getting Started classic line training Guide "counting Method"------January 23, 2015

Source: Internet
Author: User

Basic Knowledge Collation:

(1) Principle of addition

(2) Principle of multiplication

(3) The Principle of tolerance (attention to the problem of variable type)

(4) application and deformation of permutation and combination formula:

Equation of Arrangement:

The variants are:

The relationship to the composition is as follows (the first formula below is important):

The important inference of permutation combination formula:

Corollary 1:

for the first object if not taken, then we have a C (n,k+1) method, for the first object to take, I have C (n,k) way. The formula is proven .

Corollary 2:

This can reduce the time complexity of solving the two-polynomial coefficients, and it is convenient to take advantage of the recursive relations to calculate from a large order .

(5) The basic problem of permutation and combination:

Q1: The permutation of repeating elements is asked.

There are elements of K. The first element of which is NI, and the number of perfection is arranged.

According to the arrangement combination basic principles are:

Q2: A collection that can be selected repeatedly. There are n different elements, each element can be selected multiple times, a total of k elements selected, how many methods?

We can set the element I to have XI, the problem is translated into:

The solution of the problem is the number of non-negative integer solutions in the formula, so

We can get:

The solution to the problem becomes: the number of the positive integer solution of the variable in the equation. Because it is a positive integer, we can conclude that we are only able to insert (n-1) blocks (in high school) in n+k-1 to get the number of solutions for all variables .

At this point we get the result:

Q3: Monochrome triangle. n points of a given space, where there is no three-point collinear. Each of the two points is connected by a red or black line. The number of triangles with the same color for the three edges is obtained.

According to test instructions, if the direct forward enumeration, then the complexity of time is too high. We can take a complementary set of ideas, first enumerating the case is not a monochrome triangle. For each point, the points associated with it have a (n-1) edge. We can assume that the red side with the dot i has an AI bar, and the black Edge has a (N-1-ai) bar. Then the same point of the two different color sides must be able to form a unique triangle ,

So, according to the multiplication principle, we can get the number of non-monochromatic triangles for point I

There are a total of n points, and each edge is counted two times. So we need to sum up and divide by 2 to obtain the final result:

Finally we can get the number of monochrome triangles:

Over~ the small part or very attentively, hope to you casually stroll to my blog blogger helpful!!!

Algorithmic competition Getting Started classic line training Guide "counting Method"------January 23, 2015

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.