Skip to content

Commit

Permalink
update +_posts/Tech/Algorithms/2022-05-01-数学.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulong Ma committed Nov 12, 2023
1 parent a69f9b3 commit f02154d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions _posts/Tech/Algorithms/2022-05-01-数学.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ tags: Algorithms
- 球相同,盒子不同,可以有空盒。对于每个盒子,我们都给他一个球,那么上一个问题就和这问题一样了,所以我们可以看做自己有 n+m 个小球,然后我们在排列完之后在每一组都删去一个小球,这样就能枚举出有空盒的情况了。`C(n+m-1,m-1)`
- 其他复杂情况看参考。



## 容斥原理

[参考](https://leetcode-cn.com/problems/rectangle-area-ii/solution/ju-xing-mian-ji-ii-by-leetcode/)

![image-20220228201935551](https://cdn.jsdelivr.net/gh/mafulong/mdPic@vv3/v3/20220228201935.png)

定理:

![image-20220228202026269](https://cdn.jsdelivr.net/gh/mafulong/mdPic@vv3/v3/20220228202026.png)

容斥原理在排列组合里常用。

比如[100127. 给小朋友们分糖果 II](https://leetcode.cn/problems/distribute-candies-among-children-ii/) 合法方案数 = 总方案数 - 不合法方案数。不合法方案就是A,B,C的并集,然后要A+B+C求和后还要多减去一些重叠的部分。

插板法求各方案数。 用容斥定理将重叠的不合法方案数求出。

## 等差等比数列

> [参考](https://wenku.baidu.com/view/0c5e350102020740be1e9b79.html)
Expand Down Expand Up @@ -602,15 +620,7 @@ class Solution:

<img src="https://cdn.jsdelivr.net/gh/mafulong/mdPic@vv3/v3/20220603233141.png" alt="image-20220603233141181" style="zoom:25%;" />

## 容斥原理

[参考](https://leetcode-cn.com/problems/rectangle-area-ii/solution/ju-xing-mian-ji-ii-by-leetcode/)

![image-20220228201935551](https://cdn.jsdelivr.net/gh/mafulong/mdPic@vv3/v3/20220228201935.png)

定理:

![image-20220228202026269](https://cdn.jsdelivr.net/gh/mafulong/mdPic@vv3/v3/20220228202026.png)

##

Expand Down

0 comments on commit f02154d

Please sign in to comment.