EVERYTHING HAPPENS FOR THE B|

wnsyou

园龄:2年4个月粉丝:19关注:16

2023-10-10 02:03阅读: 76评论: 0推荐: 0

组合数学

排列组合

OI-wiki Link

排列组合是组合数学的基础,排列就是取出部分数字进行排序,组合就是不考虑顺序。

排列组合的中心问题是研究给定要求的排列和组合可能出现的情况总数。

加法、乘法原理

加法原理:一个东西有 n 类办法,第 i 类办法分 ai 种,总共就有 1inai 种。

乘法原理:一个东西有 n 个步骤,第 i 步有 ai 种方法,总共就有 1inai 种。

排列数与组合数

排列数,代表的是从 n 个数中任选 m 个元素在考虑顺序的情况下有多少种情况。

排列数的公式:Anm=n×(n1)×(n2)×(nm+1)=n!(nm)!

组合数也差不多,但是不考虑顺序。

组合数的公式:(nm)=Cnm=Anmm!=n!m!(nm)!

tips:组合数也被称为「二项式系数」。

组合数求解-帕斯卡公式

Cnm=Cnm1+Cn1m1

组合数求解-预处理逆元

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int n, inv[N], X[N], F[N];
inline int C (int a, int b) {
return (a >= b ? 1ll * F[a] * X[b] % mod * X[a - b] % mod : 0);
}
inline int A (int a, int b) {
return (a >= b ? 1ll * F[a] * X[a - b] % mod : 0);
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
inv[1] = X[0] = F[0] = 1;
for (int i = 2; i <= n; i++)
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for (int i = 1; i <= n; i++)
X[i] = 1ll * X[i - 1] * inv[i] % mod, F[i] = 1ll * F[i - 1] * i % mod;
return 0;
}

二项式定理

(x+y)n=i=0nCnixniyi

卢卡斯定理

卢卡斯定理可以求大数的 Cnmmodp

对于非负整数 n,mCnmCnmodpmmodp×Cnpmp(modp)

递归实现即可。

int lucas (int n, int m) {
return (!m ? 1 : 1ll * lucas(n / mod, m / mod) * C(n % mod, m % mod) % mod);
}

多重集排列

有一个多重集,元素种类为 n,第 i 个元素有 ai 个。

那么多重集的 n 排列数为 n!1inai

多重集的 r 组合数就是 Cn1r+n1

抽屉(鸽巢)原理

OI-wiki Link

鸽巢(the pigeonhole principle)原理,通常用于求解一些比较极端的情况。

最基础:如果有 n+1 个物品放入 n 个抽屉里,至少有 1 个抽屉至少有 2 个物品(反证法)。

进阶:如果有 k 个物品放入 n 个抽屉里,至少有 1 个抽屉至少有 kn

容斥原理

OI-wiki Link

容斥原理的思想大致就是在求总量时,可以先不管重不重复,求出总和后再减去重复部分。

二元容斥:|AB|=|A|+|B||AB|

三元容斥:|ABC|=|A|+|B|+|C||AB||AC||BC|+|ABC|

把它推广一下就是我们熟知的容斥原理了。

卡特兰数 Catalan

OI-wiki Link

卡特兰数 Hn 可以求解以下问题:

  • 长度为 2n 的合法括号序列的个数。
  • 在圆上选择 2n 个点,将这些点成对连接起来使得所得到的 n 条线段不相交的方法数。
  • ......

求解式:

  1. Hi=C2nnn+1
  2. Hi={0j<iHj×Hij1i>00i=0
  3. Hi={4n2n+1×Hi1i>00i=0

本文作者:wnsyou の blog

本文链接:https://www.cnblogs.com/wnsyou-blog/p/combination_math.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   wnsyou  阅读(76)  评论(0编辑  收藏  举报
  1. 1 勝利への道 安藤浩和
  2. 2 Minecraft’s End Eric Fullerton
  3. 3 月光曲完整版 贝多芬 云熙音乐
  4. 4 平凡之路 (Live版) 朴树
  5. 5 Minecraft C418
  6. 6 Paradise NiziU
  7. 7 叫我,灰原哀 龙大人不喷火
  8. 8 心机之蛙,一直摸你肚子 ——《名侦探柯南》原创同人曲 炊饭,叶辞樱,温海,寒砧,南柯柯,小茜玛姬,盛姝,阿崔Ac,贝壳初,千湛,兮茶子DaYu,乔慕,黎鹿北,起千温卿,遮阳伞,曲悠
  9. 9 战 歌 此去经年
Minecraft’s End - Eric Fullerton
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

I see the player you mean.

It is reading our thoughts as though they were words on a screen.

They used to hear voices.

Before players could read.

Sometimes disturbing.

Sometimes beautiful indeed.

Does it know that we love it?

That the universe is kind?

A million years ago,it still works

in the reality behind

and the universe said I love you

and the universe said you are the daylight

and the universe said you are not alone

and the universe said you are the night

Once we were called

the spirit of the mountain.

WHO ARE WE

Father sun

Mother moon

Gods demons angels aliens

the player,too.

WE ARE THE UNIVERSE.

We are EVERYTHING you think isn‘t you.

You are alive

ON A FLAT

INFINITE WORLD

generated by a source code

a million years old

and the universe said I love you

and the universe said you are the daylight

and the universe said you are not alone

and the universe said you are the night

Take a breath,now

Take another

Feel air in your lungs.

dreamed it was lost in a story.

and the game was over

Wake up.

加载中…

{{tag.name}}

{{tran.text}}{{tran.sub}}
无对应文字
有可能是
{{input}}
尚未录入,我来提交对应文字
评论
收藏
关注
推荐
深色
回顶
收起
点击右上角即可分享
微信分享提示