In combination with the count

Combinatorics and counting

Even though this is a small Austrian, but can stop nest to learn it again (laughs

Overall, counting problem in \ (NOIp \) in or possession of a seat.

Fast over again.

The basic counting principle

Some of the principles: the principle of addition, subtraction principle, the principle of multiplication.

Inclusion-exclusion principle:

Well understood, draw a Venn diagram to quickly understand.

img

Timothy slightly root law:

$C_S(P∩Q)=(C_SP)∪(C_SQ)C_S(P∩Q)=(C_SP)∪(C_SQ) $
\(C_S(P∪Q)=(C_SP)∩(C_SQ)\)

Counting Problems common techniques:

  • When a number of things to have a direct statistical nature more difficult, considering the statistics do not have a number of things of this nature, then subtract the total value.
  • Put forward its solution set to become the complement of the intersection , the two are equivalent.
  • Direct current count and size difficult, but relatively easy to count the size of the intersection (or vice versa), may also be converted to Morgan laws or intersection and complement.
  • When we need to calculate the number of programs with a number of special conditions, can use some equivalent alternative method. Specifically, we construct a two-shot (one mapping), the program for each of the original problem of mapping program as a new question, and the answer is easier to calculate.

Binding method: method, also known as a whole, while the counter, if the required number of items adjacent, they may be counted as a whole.

Interpolation Method: If the required number of items pairwise adjacent, other items can be put away first, and then inserting null Among these items, counted.

Method separator: the allocation indistinguishable article Solutions integer conversion / indeterminate equation for the interposer combinatorial problems.

Look at a few examples.

1. n identical apple k divided to individual requirements of each person assigned to at least one of the number of seeking solutions.

Solution: The method of the separator, this problem is equivalent to the \ (n-\) different articles into \ (K \) parts, i.e., \ (\ {n--dbinom. 1. 1-K {}} \) .

In fact, it can be seen as indeterminate equation Solutions \ (\ sum ^ n_ {i = 1} x_i = n \) total number of elements in the set of solutions of this equation.

Variant 2: the n identical apple given to individuals k, 0 can be assigned to each person, seeking the number of programs.

Solution: partition is still law, we imagine adding \ (k \) of air apple (limit case no one got the apple), assigned to this person the equivalent of Apple's apple assigned to 0, then the problem is transformed into the \ (n + k \) th article is divided into \ (K \) parts, i.e., \ (\ {n-dbinom-K +. 1. 1-n-} {} \) .

Permutations

According to the principle of multiplication, easy to draw:
\ [\ dbinom {n-m}} = {C_n ^ m = \ n-FRAC {!} Of P_n \\ ^ m = \ {n-FRAC! {M} {(nm)!!} ! (nm)} \]
few simple nature:
\ [\ {n-dbinom} = {0}. 1, \ dbinom. 1 {{}} = n-n-, \ dbinom {n-2} = {} \ {n-FRAC (n-1)} {2 } \\ \ dbinom {n} {m} = \ dbinom {n} {nm} \\ \ frac {m} {n} \ dbinom {n} {m} = \ dbinom { n-1} {k-1
} \] combination of several recursion formulas:
\ [\ dbinom {n-m} = {} \ {n--dbinom. 1. 1-m}} + {\ dbinom {{}. 1-n-m }, k> 0 \]
general method logarithmically composition:

  • Recurrence
for(int i=0;i<n;++i){
    C[i][0]=1;
    for(int j=1;j<=i;++j){
        C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
}
  • Inverse (modulo p in the sense)

Pre-skills: For any integer \ (the X-\) , it is in the mold \ (p \) divided by the sense of an integer \ (y \) is the answer to it is equivalent to the divisor multiplied by the inverse element.

\ (A / B \ {P} MOD INV = A * (B) \ {P} MOD \) , where \ (INV \) represents the inverse element.
\ [\ Begin {align} \ dbinom {n} {m} \ mod p & = \ frac {n!} {M! (Nm)!} \ Mod p \\ & = n! * Inv (m!) * inv ((nm)!) \ mod p \\ & = n! * (m! * (nm)!) ^ {p-2} \ mod p \ end {align} \]

With fast power can be.

  • lucas

I do not know.

Binomial theorem

In fact, this theorem is obvious.
\ [(X + y) ^ n = \ sum ^ n_ {k = 0} \ dbinom {n} {k} x ^ {nk} y ^ k \]
to look at a few examples.

1. derangement: there are n envelopes and letters n, correspondence, each seeking the number of programs are installed wrong letter envelope.

Solution: Using the inclusion-exclusion principle , they consider the intersection of complement, which obviously can do with inclusion and exclusion. For a given \ (k \) letter, we assume that they are installed on, then the program number is \ ((nk)! \) Species. Designated \ (K \) number of letters of the program is \ (\ {n-dbinom {K}} \) , according to the principle of multiplication, we get the answer: \ (\ SUM _} ^ {n-K = {0} (- ! 1) ^ k \ dbinom { n} {k} (nk) = \ sum ^ {n} _ {k = 0} (- 1) ^ k \ frac {n!} \) {k!}

2.JSOI2011 sub-specialty

Student has n, m kinds of specialty, each specialty a_i $ a $, distributed to each student needs to meet each assigned at least one, the number of required program.
n-, m ≤ 1000, \ (a_i \) ≤ 1000. The answer to \ (9 + 10 ^ 7 \) modulo.

Solution: This is actually a variant of the partition law, we need answers to statistics up to. Consider a practice of inclusion and exclusion, that is the same as above that question, consider the intersection and complement. Suppose \ (k \) classmates did a native assigned to the program number \ (f (k) \) . The answer is easy: \ (\ SUM of N_ ^ K = {0} (-. 1) ^ K \ {n-dbinom F} {K} (K) \) . Consider \ (F (K) \) , because \ (m \) species native, their contribution to the solution independently of each other, so we count each time the answer to the native, obtained by the above formula becomes gapped plug the total number of program plate: \ (F (K) = \ ^ m_Low Prod. 1 = {I} \ {a_i dbinom + (NK) -1-NK. 1}} {\)

Easy to see that these problems are of the same nature, that is, the front is more difficult to solve the set, we will try to convert to solve the intersection and complement the set, and then with the inclusion-exclusion to solve this intersection.

Inclusion and exclusion in selected provinces seem as relatively simple? Whether he, my dish.

In fact, it is quite well understood.

Guess you like

Origin www.cnblogs.com/DarkValkyrie/p/11279866.html