N 选择 K 公式
组合被描述为从给定序列中选择一个、两个或几个元素的过程,与它们出现的顺序无关。如果您从仅包含两个元素的系列中选择两个组件,那么首先,这些元素的顺序无关紧要。
组合配方
当从序列中的 n 个元素中选择 r 项时,组合的数量为
nCk =
例如,让 n = 5 和 r = 2,那么从一组五个中选择两个组件的方法数 = 5 C 2 = 5! /2! (5 - 2)! = 10。
值得一提的是,如果要从n个分量的集合中得到r个组合,并且这样的元素可以重复,那么
n+r−1Cr = n+r−1Cn−1
类似问题
问题 1. 有多少长度为 5 的二进制字符串在字符串某处恰好有两个 1?
解决方案:
Note that the order of the bit is not important in this case because we are concerned with the number of ones in the said string and not their order. Thus, we need to apply the concept of combinations to find the required value.
Here, n = 5 and r = 2.
C(5, 2) =
= 10
So there are 10 bit strings of length 5 with exactly two 1’s in them.
问题 2:如果要从 7 名男性和 6 名女性中选出一个由 5 人组成的委员会,找出其中至少有 3 名男性参加的人数。
解决方案:
At least three men on the committee means we can have either exactly three, four or all five men in the committee.
Number of arrangements when there are 3 men and 2 women on the committee = (7C3 × 6C2) = 525
Number of arrangements when there are 4 men and 1 woman on the committee= (7C4 × 6C1) = 210
Number of arrangements when there are all 5 men on the committee = (7C5) = 21
Total arrangements = 525 + 210 + 21
= 756
问题 3. 找出元音总是一起出现的单词“LEADING”的字母排列数?
解决方案:
If the vowels are to appear together, they would form a separate letter in the word. Hence we are left with 4 + 1 = 5 letters, which can be arranged in 5! = 120 ways.
Furthermore, there are 3! = 6 ways to arrange the vowels together.
Total number of ways of arranging the letters = 120 × 6 = 720.
问题 4. 找出由 8 个辅音和 5 个元音组成的有 4 个辅音和 3 个元音的单词的数量。
解决方案:
Number of ways of selecting 4 consonants out of 8 and 3 vowels out of 5 = 8C4 × 5C3
=
= 70 × 10 = 700
Number of ways of arranging the 7 letters among themselves = 7! = 5040
Number of words that can be formed = 5040 × 700 = 3528000.
问题 5. 有多少长度为 8 的位字符串具有相同数量的 O 和 1?
解决方案:
You are choosing from a set of eight symbols {1, 1, 1, 1, 0, 0, 0, 0} (which would normally give 8! = 40320 choices, but you have three identical “1″s and three identical “0”s so that reduces the number of options to
=
= 70 bit- strings
问题 6. 有多少个 8 位字符串至少有两个连续的 O 或两个连续的 1?
解决方案:
An 8 bit string could represent all numbers between 0 and 28 = 256.
Two consecutive zeroes can start at position 1, 2, 3, 4, 5, 6 or 7.
Starting at position 1: Strings of the form [0 0 x x x x x x]
Remaining 6 places can be arranged in 26 = 64 ways.
Starting at position 2: Strings of the form [1 0 0 x x x x x]
Remaining 5 places can be arranged in 25 = 32 ways.
Similarly, the count for positions 3, 4, 5, 6 and 7 comes to be 32 each.
Number of ways = 64 + 32 + 32 + 32 + 32 + 32 + 32 + 32 – 10
= 246
Also number of strings that start with 2 consecutive 1’s = 246
Thus required value = 246 + 246 = 492
问题 7. 有多少个 8 位字符串连续包含至少两个 0?
解决方案:
The total number of 8−bit strings (Since, you are talking about ‘strings’, I assume leading zeroes are valid) = 256
The total number of strings where we don’t have consecutive 0’s = 9C0 + 8C1 + 7C2 + 6C3 + 5C4
= 55
The number of 8 bit strings where we have consecutive 0 s = 256 – 55
= 201