Hat check problem的解决办法

来源:互联网 发布:解放军军粮 知乎 编辑:程序博客网 时间:2024/06/05 04:06

Hat Check problem 最开始源于 1713 年Montmort  提出的。 问题的表述如下:

A group of n men enter a restaurant and check their hats. The hat-checker
is absent minded, and upon leaving, she redistributes the hats back to the
men at random. What is the probability Pn that no man gets his correct
hat, and how does Pn behave as n approaches infinity?

这个问题属于组合数学中(combinatorial mathematics)错排问题(derrangements)。 所谓的derrangements, definition 如下:

derangement is a permutation of the elements of a set such that none of the elements appear in their original position。

下面将介绍三种solution, 分别为:

(1)Using the inclusion-exclusion principle(使用容斥原理)

(2)Using the recurrence relation Pn = Pn-1 - 1/n (Pn-1 - Pn-2 )(使用递归关系)


最后, 我们更进一步, 考察:

What is the expected value of the number of men who receive their correct
hats?


方法一: (使用容斥原理)

Total number of ways in which hats can be returned is 10! (10 factorial = 10 x 9 x 8 x … 1).  use theprinciple of inclusion and exclusion. Say A1 is the set of cases in which the first guest receives his own hat back. Then, we can enumerate:

The cases in which some guest(s) receive their own hats back are: A1 U A2 U … U A10


(其中令n 为10 即可)

By symmetry, 我们有:

A1 U A2 .. A10| = 10 |A1| – C(10,2) |A1 intersection A2| + C(10,3) |A1 intersection A2 intersection A3| – C(10,4) |A1 intersection A2 intersection A3 intersection A4| + C(10,10) |A1 intersection A2 intersection A3 intersection … intersection A10|

可能会用到的公式如下:


例如



最终, 我们的计算公式如下:

|A1 U A2 .. A10| = 10 * 9! – C(10,2) 8! + C(10,3) 7! – C(10,4) 6! + …. – C(10,10) 0!
= 10 * 362880 – 45 * 40320 + 120 * 5040 – 210 * 720 + 252 * 120 – 210 * 24 + 120 * 6 – 45 * 2 + 10 * 1 – 1 * 1
= 2293839

这些结果是不符合我们的要求的, 所以我们的最终的计算结果如下:

Therefore, the probability that no guest receives their hat back is 1 – 2293839/10! =0.367879464


in generality, the result below:


所以概率的一般公式为(the probability Pn that no man gets his correct
hat):




方法二: Solution Using a Recurrence Relation

下面我们推导出递归关系:

  记录Dn 为n 个元素的错排的所有个数。 那么then man #1 will not have his correct hat, 所以#1 man 具有 n - 1 中选择结果(故而要乘以n - 1)。 我们这里假设 man #1 gets hat #2. 接下来的情况可以分成下面两个cases。 如下:

case1: man #2 gets hat #1, or

case2:  man #2 does not get hat #1.

对于case1, for a derangement to occur, we need the remaining n-2 men to get the wrong hats, 所以总共的可能性为the total number of derangements is simply Dn-2.

对于case2: man #2 cannot get hat #1 (that’s case a), man #3
cannot get hat #3, man #i cannot get hat #i, etc. 现在我们需要换个perspective, 也就是说, 此时位置1 的可以取代2的位置作为“2”, 也就是说, 2 不能在‘2’(其实是1), 3不能在3, ...等等, 共有n - 1 个men, 我们需要求derangement  Dn-2, 最终我们得到如下递归式子:


其中, base case 为:


NOTE: 当Dn 是n!的时候, 满足上述式子, 即:



上述递归式子的求解如下得到:




问题三: What is the expected value of the number of men who receive their correct
hats?

这里使用indicator random variables 求解:














0 0
原创粉丝点击