2.3 permutations and combinations
1 . Arrange (care order)
All: N everyone to line up, Captain for N. The first position can choose N, the second place can choose N-1, and so on:P (n,n) =n (n-1) (n-2) ... 3*2*1=n! ( stipulated 0!=1).
Partial arrangement: N Person m to queue (m<=n). The first position can be selected N, the second position can choose N-1, and so on, the number of M (the last one) can be selected (n-m+1), to:
2 . Combination ( don't care about order)
N Individuals m (m<=n) come out, do not queue, do not care about the order C (n,m). If you care about the arrangement then it is P (n,m), if you don't care about it, then eliminate the repetition, then how much? The same elected m individuals, they also want to "full row" to get P (n,m), so you have to:
Properties of the number of combinations 1:C (n,k) =c (n-1,k) +c (n-1,k-1)
Properties of the number of combinations 2:n&k==k C (n,k) is odd, otherwise even
3 . Other permutations and combinations
( 1 round Arrangement:n Individuals all come in a circle of Q (N,n), which has been lined up in a circle, disconnected from different positions, and changed into a different queue. So:q (n,n) *n=p (n,n) à>>> q (n) =p (n,n)/n= (n-1)!
So, part of the round row Q (n,r)=P (n,r)/r=n!/(r* (n-r)!)
( 2 ) repeating arrangement ( Limited ): K different balls, the number of each ball is A1,A2,... AK,
Set N=a1+a2+...+ak, the total number of n balls, for
n!/(a1!*a2!*...*ak!)
( 3 ) repeating combinations ( Infinity ): N Different balls, the number of each ball is infinite, from the selected K out,
Without permutations, which are combinations, for C (n+k-1,k)
Proof: Assuming the selected number (ordered) 1<=b1<=b2<=b3......<=bk<=n
The difficulty of this problem is the = number, now remove the = number, so there are:
1<=b1<b2+1<b3+2<b4+3......<bk+k-1<=n+k-1
The middle or the number of K! However, it is not a B-series, but the C-series assumes c[i]:=b[i]+i-1, so the 1<=c1<c2<c3<c4.......<ck<=n+k-1 so the problem begins to convert to a no-repeat combinatorial problem, that is, in n+ K-1 the number of combinations of k in the selected element C (n+k-1,k).
(4) nonadjacent arrangement : 1~n This n natural number is K, and the combination of any two number of nonadjacent numbers in this k number has a C (n-k+1,k) certificate and (3) the same.
(5) dislocation arrangement (abbreviation : wrong row)
First do a small problem: 5 book, the number is 1,2,3,4,5, now to put the 5 book is placed on the bookshelf of the number 1,2,3,4,5, request the number of the book and the bookshelf number is not the same, how many kinds of different placement method?
Example: N players with a numbered,.... n on the chest live in N rooms numbered,.... n respectively. It is stipulated that each person should live in a room, and their number cannot be the same as the number of the room.
That's the problem with the wrong row . When n=3, can only be 312 or 231 of these two.
The puzzle: recursion. At first, all the players lived in the same room as their number. Then the wrong row begins, and the nth player comes out from the first.
The first case: N want to and () any one of the players change room, other n-2 personal change room things, they don't care. The number of n-2 of the other players is d[n-2],n can be swapped with the front 1~ (n-1), so there is (n-1) a d[n-2].
The second case: n wants to change rooms with any of the players, but N wants to live in the first room, and N doesn't want to stay in the first room.
Maybe you would think: then you can stay in the room and live in the room. Excuse me, why do you get angry in the beginning to find not directly to find, ~ ~ (╯﹏╰) ~ ~
No way, the code of his own chest replaced, he pretended to be, then the wrong platoon 1~n-1 (that is, d[n-2]). , so you don't stay in the room. So there are (n-1) a d[n-1].
If you understand the above two plus blue places, then the wrong line of formula is out.
There are also
Dislocation permutation sequence is 0,1,2,9,44,265 ...
(7) Catalan sequence
1: There are 2n individuals lined up into the theatre. Admission fee is 5 yuan. of which only n individuals have a 5-dollar bill, the other N people only 10 yuan banknotes, the theater no other banknotes, asked how many of the methods so long as there are 10 of people buy tickets, the ticket office has 5 yuan of money change?
2: A barrister in a big city works N blocks north of her residence and N blocks east. Every day she walks 2n blocks to work. If he never crosses (but can touch) the diagonal from home to the office, how many possible roads are there?
3: Select 2n points on the circle, and connect the points in pairs so that the resulting n line segments do not intersect the number of methods?
4: How many ways to divide a convex polygon area into a triangular area when the diagonal does not intersect?
5: A stack (infinity) of the stack sequence is three-in-one,.. N, how many different out-stack sequences are there?
How many different two-fork trees can be built with a 6:n node?
7:n a different number in the stack, in order to find out the number of different results of the stack?
The corresponding sequence is 1, 1, 2, 5, ===catalan, the,.... of the series.
The Jiewei of the recursive relationship
Template C + + 02 number theory algorithm 3 permutations and combinations