![be861cb546e1599e2e1d1c8bb68eafb9.png](https://i-blog.csdnimg.cn/blog_migrate/1e5d30089905f698796c0d9a94987049.jpeg)
在这一章中,我们将会简要介绍容斥原理以及其在计数中的应用。
想必大家对于容斥原理这个词语及其含义都已经十分熟悉,故我们将着重于介绍其如何应用以及一些重要的实例。对很多看似无从下手的组合计数问题利用容斥原理往往会变得意想不到的简单。
在后文中,我们总是用
![equation?tex=P_i](https://i-blog.csdnimg.cn/blog_migrate/3fe8ed650a3b02e14400504306d079ce.png)
![equation?tex=X_i](https://i-blog.csdnimg.cn/blog_migrate/721142a5fa8cc5aded491c76269ba258.png)
![equation?tex=S](https://i-blog.csdnimg.cn/blog_migrate/e6217fb4a8fa397deeec408fbaf501a3.png)
![equation?tex=%5Coverline%7BX_i%7D](https://i-blog.csdnimg.cn/blog_migrate/1d7974e2f65667950b184c36e41e12bd.png)
![equation?tex=S](https://i-blog.csdnimg.cn/blog_migrate/e6217fb4a8fa397deeec408fbaf501a3.png)
定理(容斥原理)
![equation?tex=%7C%5Coverline%7BX_1%7D%5Ccap%5Coverline%7BX_2%7D%5Ccap...%5Ccap+%5Coverline%7BX_k%7D%7C%3D%7CS%7C-%5Csum_i%7CX_i%7C%2B%5Csum_%7Bi%3Cj%7D%7CX_i%5Ccap+X_j%7C%2B...%2B%28-1%29%5Ek%7CX_1%5Ccap...%5Ccap+X_k%7C](https://i-blog.csdnimg.cn/blog_migrate/aa38b0fb7768d2fff1ffc15657cd06c6.png)
我们以往对于容斥原理的证明大多基于数学归纳法。但是事实上,我们可以利用贡献法:分别分析满足条件的元素与不满足条件的元素对于等式两端的贡献。
对于容斥原理而言,我们在
![equation?tex=S](https://i-blog.csdnimg.cn/blog_migrate/e6217fb4a8fa397deeec408fbaf501a3.png)
![equation?tex=x](https://i-blog.csdnimg.cn/blog_migrate/79271a73b75b1b2971964504afad8a27.png)
如果
![equation?tex=x](https://i-blog.csdnimg.cn/blog_migrate/79271a73b75b1b2971964504afad8a27.png)
![equation?tex=P_1%2C...%2CP_k](https://i-blog.csdnimg.cn/blog_migrate/272766f99636b6c2837af902e74b18aa.png)
![equation?tex=1](https://i-blog.csdnimg.cn/blog_migrate/227e8e885aa645310c5e4bbc05c50091.png)
![equation?tex=%7CS%7C](https://i-blog.csdnimg.cn/blog_migrate/fd75a01b4762338f5c037679faf28cb8.png)
![equation?tex=1](https://i-blog.csdnimg.cn/blog_migrate/227e8e885aa645310c5e4bbc05c50091.png)
否则,
![equation?tex=x](https://i-blog.csdnimg.cn/blog_migrate/79271a73b75b1b2971964504afad8a27.png)
![equation?tex=m](https://i-blog.csdnimg.cn/blog_migrate/f79ab5c40ded11a5ecf9c3162bbd89d5.png)
![equation?tex=1%5Cleq+m%5Cleq+k](https://i-blog.csdnimg.cn/blog_migrate/227e8e885aa645310c5e4bbc05c50091.png%5Cleq+m%5Cleq+k)
![equation?tex=0](https://i-blog.csdnimg.cn/blog_migrate/b0002d5deeecc7acffc2335d8b8c7927.png)
![equation?tex=%7CS%7C](https://i-blog.csdnimg.cn/blog_migrate/fd75a01b4762338f5c037679faf28cb8.png)
![equation?tex=1](https://i-blog.csdnimg.cn/blog_migrate/227e8e885aa645310c5e4bbc05c50091.png)
![equation?tex=-%5Csum_i%7CX_i%7C](https://i-blog.csdnimg.cn/blog_migrate/28440aa9401aa0b110f7d7db5f60256a.png)
![equation?tex=-C_m%5E1](https://i-blog.csdnimg.cn/blog_migrate/e04c6205640709360eaf335096740e19.png)
![equation?tex=m](https://i-blog.csdnimg.cn/blog_migrate/f79ab5c40ded11a5ecf9c3162bbd89d5.png)
![equation?tex=1](https://i-blog.csdnimg.cn/blog_migrate/227e8e885aa645310c5e4bbc05c50091.png)
![equation?tex=0](https://i-blog.csdnimg.cn/blog_migrate/b0002d5deeecc7acffc2335d8b8c7927.png)
![equation?tex=%5Csum_%7Bi%3Cj%7D%7CX_i%5Ccap+X_j%7C](https://i-blog.csdnimg.cn/blog_migrate/7a42e9dd7e44290cd74573777ae62c12.png)
![equation?tex=C_m%5E2](https://i-blog.csdnimg.cn/blog_migrate/fa34c3ffeeda6abbf1ee5ad8884d5fd7.png)
![equation?tex=m](https://i-blog.csdnimg.cn/blog_migrate/f79ab5c40ded11a5ecf9c3162bbd89d5.png)
![equation?tex=2](https://i-blog.csdnimg.cn/blog_migrate/f4eadc86eb43843e3f4d079c88da3369.png)
![equation?tex=1](https://i-blog.csdnimg.cn/blog_migrate/227e8e885aa645310c5e4bbc05c50091.png)
![equation?tex=0](https://i-blog.csdnimg.cn/blog_migrate/b0002d5deeecc7acffc2335d8b8c7927.png)
最终,我们得到对于等式右侧贡献为
![equation?tex=C_m%5E0-C_m%5E1%2BC_m%5E2%2B...%2B%28-1%29%5EmC_m%5Em](https://i-blog.csdnimg.cn/blog_migrate/6b34c335c8b5303b706d8aefe0f95d79.png)