Inclusion-exclusion principle study notes

official

Union

$$\left|\bigcup_{i=1}^nS_i\right|=\sum_i|S_i|-\sum_{i<j}|S_i\cap S_j|+\sum_{i<j<k}|S_i\cap S_j\cap S_k|-\cdots+(-1)^{n-1}|S_1\cap \cdots\cap S_n|$$

 

 prove

For an element $ x $, assuming that it belongs to the collection of $ T_1, T_2, \ ldots, T_m $, then its contribution to the answer is:

$$|\{T_i\}|-|\{T_i\cap T_j|i<j\}|+|\{T_i\cap T_j\cap T_k|i<j<k\}|-\cdots+(-1)^{m-1}|\{T_1\cap T_2\cap \cdots\cap T_m\}|\\=\binom{m}{1}-\binom{m}{2}+\cdots+(-1)^{m-1}\binom{m}{m}=1$$

Thus each element is calculated only once, and that is the sum of the set size

 

Intersection

$$\left|\bigcap_{i=1}^nS_i\right|=|U|-\left|\bigcup_{i=1}^n\overline{S_i}\right|$$

Collection of the U-$ where $, $ \ overline {S} $ $ is the complement of S $ $ $ of the U-

It may be set up to the right side and the calculation of inclusion and exclusion

 

prove

If the $ x \ in \ bigcup \ overline {S_i} $, then $ \ exists i, x \ notin S_i $, $ X $ i.e., the intersection does not exist, the contribution is zero, otherwise contribute to a

Thus the final size of the sum of the intersection

 

example

Wrong row problem

$ P $ arrangement number of the following conditions are determined length n-$ $ a: $ \ forall i, p_i \ neq i $

 

solution

Consider the inclusion-exclusion:
set $ S_i $ express satisfy $ p_i \ $ p $ arrange collection neq i $, then the subject of the request is $ | \ bigcap S_i | $

According to the formula:

$$Ans=\left|\bigcap_{i=1}^nS_i\right|=|U|-\left|\bigcup_{i=1}^n\overline{S_i}\right|\\=|U|-\sum_i|\overline{S_i}|+\sum_{i<j}|\overline{S_i}\cap\overline{S_j}|-\cdots-(-1)^{n-1}|\overline{S_1}\cap \cdots\cap\overline{S_n}|$$

Notice:

$$\forall a_1<a_2<\cdots<a_m,\left|\bigcap_{i=1}^m\overline{S_{a_i}}\right|=(n-m)!$$

then:

$$Ans=\sum_{m=0}^n(-1)^m\sum_{a_i<a_2<\cdots<a_m}\left|\bigcap_{i=1}^m\overline{S_{a_i}}\right|=\sum_{i=0}^n(-1)^i\binom{n}{i}(n-i)!=n!\sum_{i=0}^n\frac{(-1)^i}{i!}$$

Then you can stay in the $ O (n) $ prayed

 

Checkered coloring problem:

A square of n rows and m columns, are initially white, Black can choose some lattice asked to meet at least a number of lines per grid black solution each column

 

solution

And the title ideas similar to obtain at least $ $ I $ J $ row number of the program is not listed in the black lattice, it is $ 2 ^ {(ni) (mj)} $

According to the principle of inclusion and exclusion:

$$Ans=\sum_{i=0}^n\sum_{i=0}^m(-1)^{(i+j)}\binom{n}{i}\binom{m}{j}2^{(n-i)(m-j)}$$

Efficiency $ O (n ^ 2) $

Guess you like

Origin www.cnblogs.com/Y25t/p/12237303.html