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 求解:
- Hat check problem的解决办法
- Indicator random variables --Hat check problem
- hat check
- 算法导论5.2-4解析(hat-check problem)
- Problem check
- Red Hat Linux忘记root密码的解决办法
- red hat 未注册不能使用yum的解决办法
- Vmware 安装 Red Hat 9.0 Linux 无法联网的解决办法
- UVa Problem Solution: 10196 - Check The Check
- shasum check failed解决办法
- Hp battery check 无法使用报错的解决办法
- linux run setenforce 1 在check filesystem处报错的解决办法
- Time of error: Reason:Check the details的解决办法
- T-Sql Check IO Problem
- Unknown Android Packaging Problem 的解决办法
- vmware red hat linux9 no link present. Check cable
- UVa Problem 10196 Check the Check (将军)
- UVa Problem 10196 Check the Check (将军)
- 关于drwxr-xr-x里面的这个indicate @代表的意思以及如何解决
- 吝啬的国度
- 1-4 输出菱形
- VC解决COM启动运行中“服务器运行中”等消息问题
- C++boost库中sp_counted_impl_x实现解析
- Hat check problem的解决办法
- spark安装
- linux文件IO函数大全
- DevExpress从SpreadsheetControl拷贝粘贴到richeditcontrol
- QWebKit-QWebFrame手动加载Html文件只显示Html的Head问题
- 利用 DirectShow 开发自己的 Filter
- 使用Axis2搭建WebService环境(一)
- 通过反射动态调用类的静态方法和实例方法
- js 取得遍历函数参数