组合数学一:容斥原理
这篇随笔不是原创内容。
抄录 Stasys Jukna 所著 Extremal Combinatorics $\S 1.6~\text{The inclusion-exclusion principle}$
The principle of inclusion and exclusion (sieve of Eratosthenes) is a powerful tool in the theory of enumeration as well as in number theory. This principle relates the cardinality of the union of certain sets to the cardinalities of intersections of some of them, these latter cardinalities often being easier to handle.
For any two sets $A$ and $B$, we have
\begin{equation*}
|A \cup B| = |A| + |B| - |A \cap B|.
\end{equation*}
In general, given $n$ subsets $A_1, \dots, A_n$ of set $X$, we want to calculate the number $|A_1 \cup \dots \cup A_n|$ of points in their union. As the first approximation of this number, we can take the sum
\begin{equation}
|A_1| + \dots + |A_n|. \label{naive-sum}
\end{equation}
However, in general, this number is too large since if, say $A_i \cap A_j \ne \emptyset$ then each point of $A_i \cap A_j$ is counted two times in \eqref{naive-sum}: once in $|A_i|$ and once in $|A_j|$. We can try to correct the situation by subtracting from \eqref{naive-sum} the sum
\begin{equation}
\sum_{1 \le i < j \le n} |A_i \cap A_j|. \label{two-sum}
\end{equation}
but then we get a number which is too small since each of the points in $A_i \cap A_j \cap A_k \ne \emptyset$ is counted three times in \eqref{two-sum}: once in $ |A_i \cap A_j| $, once in $|A_j \cap A_k| $, and once in $|A_i \cap A_k|$. We can therefore try to correct the situation by adding the sum
\begin{equation*}
\sum_{1 \le i < j < k \le n} | A_i \cap A_j \cap A_k|,
\end{equation*}
but again we will get a too large number, etc. Nevertheless, it turns out that after $n$ steps well will get the correct result. This result is known as the inclusion-exclusion principle. The following notation will be handy: if $ I $ is a subset of the index set $ \{1, \dots, n\} $, we set
\begin{equation*}
A_I := \bigcap_{i \in I} A_i,
\end{equation*}
with the convention that $A_{\emptyset} = X$.
Proposition 1 (Inclusion-Exclusion Principle). Let $A_1, \dots, A_n$ be subsets of $X$. Then the number of elements of $X$ which lie in none of the subsets $A_i$ is
\begin{equation}
\sum_{I \subseteq \{1, \dots, n \}} (-1) ^ {|I|} |A_I|. \label{E:1}
\end{equation}
Proof. The sum is a linear combination of cardinalities of sets $A_I$ with coefficients $+1$ and $-1$. We can re-write this sum as
\begin{equation*}
\sum_I (-1)^{|I|} | A_I| = \sum_I \sum_{x \in A_I} (-1)^{|I|} = \sum_{x} \sum_{I \colon x \in A_I} (-1)^{|I|}.
\end{equation*}We calculate, for each point of $X$, its contribution to the sum, that is, the sum of the coefficients of the sets $A_I$ which contain it.
First suppose that $ x \in X$ lies in none of the sets $ A_i $. Then the only term in the sum to which $x$ contributes is that which $ I = \emptyset$; and this contribution is $1$.
Otherwise, the set $ J := \{ i \colon x \in A_i \} $ is non-empty; and $ x \in A_I $ precisely when $ I \subseteq J $. Thus, the contribution of $ x $ is
\begin{equation*}
\sum_{ I \subseteq J } (-1) ^ { | I | } = \sum_{ 0 \le i \le |J| } \binom{|J|}{i} (-1)^i = (1 - 1)^{ |J| } = 0
\end{equation*}by the binomial theorem.
Thus, points lying in no set $A_i$ contribute $ 1 $ to the sum, while points in some $ A_i $ contribute $ 0 $; so the overall sum is the number of points lying in none of the sets, as claimed.
For some applications, the following form of the inclusion-exclusion principle is more convenient.
Proposition 2. Let $A_1, \dots, A_n$ be a sequence of (not necessarily distinct) sets. Then
\begin{equation}
|A_1 \cup \dots \cup A_n| = \sum_{\emptyset \ne I \subseteq \{1 \dots n\}} (-1)^{ |I| + 1 } |A_I|. \label{E:2}
\end{equation}
Proof. The left-hand of \eqref{E:2} is $|A_\emptyset|$ minus the number of elements of $X = A_\emptyset$ which lie in none of the subsets $A_i$. By Proposition 1 this number is
\begin{equation*}
|A_\emptyset| - \sum_{I \subseteq \{ 1, \dots, n\}} (-1)^{|I|} |A_I| = \sum_{\emptyset \ne I \subseteq \{1, \dots, n\}} (-1)^{ |I| + 1 } |A_I|,
\end{equation*}
as desired.
- 2014ACM/ICPC亚洲区西安站 F题 color (组合数学,容斥原理)
- UVA.11806 Cheerleaders (组合数学 容斥原理 二进制枚举)
- 组合数学-容斥原理
- BZOJ1853 [Scoi2010]幸运数字 [容斥原理]【组合数学】
- HDU 1695 GCD (数论-整数和素数,组合数学-容斥原理)
- Codeforces div2 #317C Lengthening Sticks(组合数学+ 容斥原理)
- 【组合数学_容斥原理专辑】【10.4最新更新】
- HDU 1695 GCD (数论-整数和素数,组合数学-容斥原理)
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- 【组合数学】八(容斥原理)
- hdu 1695 GCD(组合数学:容斥原理)
- 2014ACM/ICPC亚洲区西安站 F题 color (组合数学,容斥原理)
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
- 2017.3.24组合数学学习——容斥原理
- UVALive 6469 Deranged Exams 组合数学+容斥原理
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- uva 10325 The Lottery(组合数学-容斥原理)
- 51nod 1667 概率好题 组合数学+容斥原理
- hdu 2204 Eddy's爱好 [容斥原理]【组合数学】
- poj 1091 跳蚤(组合数学-容斥原理)这题要求的数据范围根本就是胡说八道!