有多少长度为 8 的位字符串具有相同数量的 0 和 1?
排列是给定数量的组件的许多配置,或者通过一个接一个地选择,其中一部分,或者一次全部选择。它们是将线性序列分配给系列成分的过程。重新排序特定序列或系列的元素的过程也称为重新排序。换句话说,排列一个序列需要列出该序列的所有替代排列。例如,序列 1, 2 可以用两种不同的方式表示:1, 2 或 2, 1。
置换公式
当 n 个元素按特定顺序排列 r 个项目时,排列的数量为,
nPr = n! / (n – r)!
For example, let n = 5 and r = 2. The number of permutations is 5P2 = 5! / (5 – 2)! = 20.
组合
它被描述为从给定序列中选择一个、两个或几个元素的过程,与它们出现的顺序无关。如果您从仅包含两个元素的系列中选择两个组件,那么首先,这些元素的顺序无关紧要。
组合配方
当从序列中的 n 个元素中选择 r 项时,组合的数量为
nCr = n! / r! (n – r)!
For example, let n = 5 and r = 2, then the number of ways to choose two components from a set of five = 5C2 = 5! / 2! (5 – 2)! = 10.
值得一提的是,如果要从n个分量的集合中得到ar个组合,并且这样的元素可以重复,那么
n+r-1 C r = n+r-1 C n-1
有多少长度为 8 的位字符串具有相同数量的 0 和 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
类似问题
问题 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 x 6C2) = 525
Number of arrangements when there are 4 men and 1 woman on the committee= (7C4 x 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 x 6 = 720.
问题 4. 找出由 8 个辅音和 5 个元音组成的有 4 个辅音和 3 个元音的单词的数量。
解决方案:
Number of ways of selecting 4 consonants out of 8 and 3 vowels out of 5 = 8C4 x 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. 如果不允许重复,“GEEKSFORGEEKS”这个词可以组成多少个四个字母的词?
解决方案:
Since there are 7 different letters in the word ‘GEEKSFORGEEKS’
Required number of words = 7P4
= 7! / 3!
= 840