Fundamentals of Computer algorithms-mathematics (permutation and combination functions)

Source: Internet
Author: User
Tags repetition

One arrangement

1. The total number of R elements arranged from n elements

Pnr=p (n,r) =n (n-1) (n-2) ...                  (n-r+1) =n!/(n-r)! Example: N A ball takes r a different box, each box a ball, how many kinds of putting

2. Full arrangement of n elements

Pnn=p (n,n) =n!

3. Example: Randomly selected n (n<365) individuals, in which at least two people have the same probability of birthday.

Number of series of birthdays of n individuals: 365n

n the probability that a person's birthday is different: P (365,n)

Therefore: 1-p (365,n)/365n

4. Round arrangement

Take r elements from n elements along a circumference

QNR = PNR/R (the result of the arrangement of r elements is compared with the result of the circular arrangement, and each permutation repeats R times)

Similarly: Qnn = n!/n = (n-1)!

Two combinations

1. CNR: Arrange the R elements from n elements without regard to the order;

such as: N Ball take R a box, R box is the same.

If the box is arranged on the basis of the result of each combination, the arrangement of N takes R is obtained:

Cnr r! = Pnr so Cnr = pnr/r! = n!/(n-r)!r!

2 grouping

With A1,a2...a8 eight-bit members, 22 pairs, divided into 4 groups, trial solution N

Method One: Select: A1 There are also 7 options, the remaining 6 people, choose the same 5 options, the remaining 4, one of the options is also 3 possible; n=7*5*3

Method Two: Full arrangement and grouping (intra-group, inter-group):

The 8 members are all arranged in a total of 8! Possible, if divided into 4 groups, {12}{34}{56}{78}, if the position in the group is interchangeable, for the selection also has no effect, then the whole arrangement of the selection of the same repetition, repeat number: 2n

At the same time, the arrangement between the 4 groups does not affect the same relationship, so the whole arrangement of the same relationship also has a repetition, repeat number: 4!

So 8!/(2n*4!)

Method Three: First grouping, then group inside

8 people were divided into 4 groups, the 1th group had C82 Choice, the 2nd group had C62 species choice, and the 3rd group had C42 choice; The order of the groups was irrelevant

n= c82* c62*c42 * c22/4! =105

3 Allow duplicate combinations

Theorem 1: Combining r in n different elements, allowing repetition (elements in R elements are repeatable), number of combinations:cn+r-1r

Theorem 2: The R-no-difference ball, put in N marked box, each box can more than one, then a total of Cn+r-1r Scheme

Example: (x+y+z) 4 Total number of items:

It is equivalent to putting 4 balls into 3 boxes, and there is no limit to the number of boxes in each one. As X4 can be understood to put 4 balls into box X.

N=c (n+r-1,r) =c (3+4-1,4) =c (6,4) =15

4 Non-contiguous combinations

Refers to: from the sequence a={1,2,.... n} takes R, which does not exist, i,i+1 two neighbors appear in the combination of a combination.

Theorem: Take R as an nonadjacent combination from the sequence a={1,2,.... n}, where the combined number is:Cn-r-1r

Three-female function-power series

Definition: Set a0,a1,a2...an is a sequence that defines its parent function as a power series —————————— solve the combinatorial problem of element repetition

FA (x) = (1+x) a =c (a,0) X0 +c (a,1) X1 +c (a,2) X2 +c (a,3) X3 +.....+c (a,n) xn+

The relationship between the parent function and other parent functions:

A (x) = 1/(1-x) = 1+x+x2+x3 +.....+xn+

B (x) =1/(1-x) 2 =a (x)/(1-x) = 1+2x+3x2+4x3 +.....+nxn-1

C (x) =1/(1-x) 3 =b (x)/(1-x) = 1+3x+6x2+10x3 +.....+


Application:

Example 1: Red ball Two, white ball, yellow ball each one, how many different combinations of number

Use: FA (x) = (1+x) a =c (a,0) X0 +c (a,1) X1 +c (a,2) X2 +c (a,3) X3 +.....+c (a,n) xn+ Each of these indices represents the number of choices, and the coefficients represent the number of scenarios for that selection.

The number of R ball combinations is CR, then C0, C1, C2, C3, C4 's parent function:

G (x) = (1+x+x2) (1+x) (1+x) =1+3x+4x2+3x3+x4

1+x+x2 that the first red ball selected 0, choose one, choose Two

Total: 1+3+4+3+1=12 of different combinations.

The combination number of 2 balls selected by 4x2 is 4;3x to indicate the number of combinations of 1 balls selected.

Example 2: If there are 1g,2g,3g,4g weights each, ask can weigh several possible weights.

Use: FA (x) = (1+x) a =c (a,0) X0 +c (a,1) X1 +c (a,2) X2 +c (a,3) X3 +.....+c (a,n) xn+ Each of these indices represents the weight, and the coefficients represent the number of schemes for that weight.

The female function is: G (x) = (1+x) (1+x+x2) (1+x+x2+x3) (1+x+x2+x3 +x4)

Add the coefficients and you get the answer.

Example 3: If there is a weight of 1g 3, 2g weight 4, 4g weight 2, ask what weight can be weighed, there are several options.

G (x) = (1+x+x2+x3) (1+x2 +x4+x6+x8) (1+x4+x8)

Four-female function-exponential type

Definition: Set a0,a1,a2...an is a sequence that defines its parent function as an exponential parent function:--solving the permutation problem of element repetition

FA (x) = (1+x) a =c (a,0) X0 +c (a,1) x1/1! +c (a,2) x2/2! +c (a,3) x3/3! +.....+c (a,n) xn/n!+

Example 1:

8 elements, A1 repeats 3 times, A2 repeats 2 times, A3 repeats 3 times, from which R combinations are taken, and the parent function of their combined number:

G (x) = (1+x+x2+x3) (1+x2) (1+X+X2+X3) =1+3x+6x2+9x3+10x4+9x5+6x6+3x7+x8

Can be obtained, if take 4 elements to combine there are 10 kinds of schemes. If you need to arrange 4 elements: The problem is transformed from 8 elements to 4, and the number of permutations should be the arrangement of each combination.

Such as: x1x33 represents 1 a1,3 a A3; Then it corresponds to the number of permutations of 4!/1!3!;

By:

CNR = pnr/r!

Ge (x) = (1+x/1!+x2/2!+x3/3! ) (1+x/1!+x2/2!)  (1+x/1!+x2/2!+x3/3! )=

1+ 3x/1! + 9x2/2! + 28x3/3! + 70x4/4! + 170x5/5! + 350x6/6! + 560x7/7!+ 560x8/8!

The number of permutations of k here should be k!. Therefore, the number of permutations of 4 should be: 70;

Example: A1,a2...a7 for 7 different balls, put them into 4 marked boxes, require 1th, 22 boxes must contain an even number of numbers, the 3rd box contains an odd number of numbers. How many methods are there?

Can be understood as taking 7 of the 4 numbers from the 1,2,3,4 to allow repeating permutations ———— elements

Example: 1,3,5,7,9 the number of n-digits consisting of 5 digits, which requires that 3 and 7 appear in an even number of times, the number of other numbers is unlimited.

Fundamentals of Computer algorithms-mathematics (permutation and combination functions)

Related Article

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.