十层楼
Ten Floor Building
题目详情
一栋大楼的地下室以上有10层。如果 12 个人进入地下室的一部电梯,并且每个人都独立于其他人随机选择一个楼层出去,那么你预计电梯会在多少层停下来让这 12 个人中的一个或多个出去?
A building has 10 floors above the basement. If 12 people get into an elevator at the basement, and each chooses a floor at random to get out, independently of the others, at how many floors do you expect the elevator to make a stop to let out one or more of these 12 people?
解析
我们可以通过使用指标随机变量来解决这个问题。为了快速回顾一下,指标随机变量通常用于将较大的随机变量分解为较小的二元成分。在这个问题中应用二元随机变量会将 10 层楼分解为单独的楼层。
例如,设 为随机变量,表示电梯停在的楼层数。问题是要求 或 的期望。然而,我们可以将分解为10个指标随机变量的总和;我们将它们表示为 。每个 都是下限 的指示随机变量。详细来说,如果12个人中有一个在3楼下车,那么。如果8楼无人下车,则。
然后这个问题简化为寻找 (通过期望线性)。我们现在需要计算 。然而,由于对称性(每个楼层与其他楼层无法区分并且具有相同的分布),我们可以简单地求解 以获得通用 (并且 之和变为 ,因为所有 都是分布中的等效随机变量)。
指标随机变量的期望等于随机变量等于 1 的概率(该结论来自期望的定义)。所以问题就简化为寻找。口头上说,这是要求有人(至少 1 人)在 层下车的概率。
我们可以使用补码规则来求解这个表达式。 。 是 层无人下车的概率。单人在 楼层不下车的概率为 (选择除 楼层外的任意楼层)。因此,由于所有 12 个人以相同的可能性且彼此独立地选择楼层,因此所有 12 个人选择不在楼层 下车的概率为 。
因此,。向上级联,这意味着 。这意味着 。因此,电梯预计将停在 10 层楼中的 7 层左右,让 12 人下车。
这是一个说明此解决方案的 python 程序:
import random
def simulate_trial() -> int:
# each of the 12 people pick a random floor between 1 and 10
floors = [random.randint(1, 10) for _ in range(12)]
# count the number of unique floors the elevator must stop at
return len(set(floors))
# list of the number of floors the elevator stopped at for each trial
res = [simulate_trial() for _ in range(10_000)]
# compute the average, or expected number of floors the elevator needed to stop at over all 10,000 trials
print(sum(res) / len(res))Original Explanation
We can solve this problem through the use of indicator random variables. For a quick recap, indicator random variables are often used to decompose a larger random variable, into smaller, binary constituents. The application of binary random variables in this problem would be breaking down the 10 floors into solitary floors.
For example, let be the random variable indicating the number of floors the elevator stopped at. The question is asking for the expectation of , or . However, we can break down into the sum of 10 indicator random variables; we’ll denote them . Each is an indicator random variable for floor . To elaborate, if one of the 12 people gets off on floor 3, then . If nobody gets off on floor 8, then .
This problem then reduces to finding the (by Linearity of Expectation). We now need to compute the . However, due to symmetry (each floor is indistinguishable from the other and has identical distribution) we can simply solve for for a generic (and the sum becomes since all are equivalent random variables in distribution).
The expectation of an indicator random variable is equal to the probability of the random variable equalling 1 (this conclusion follows from the definition of expectation). So the problem reduces to finding . Stated verbally, this is asking for the probability that someone (at least 1) gets off at floor .
We can solve for this expression using the complement rule. . is the probability that nobody gets off on floor . The probability that a single person does not get off on floor is (he/she chooses any floor except floor ). Therefore, since all 12 people choose floors with equal likelihood and independently of each other, the probability that all 12 people choose not to get off at floor is .
Therefore, . Cascading upwards, this means . And this means . So the elevator is expected to stop at around 7 of the 10 floors to drop off the 12 people.
Here is a python program that illustrates this solution:
import random
def simulate_trial() -> int:
# each of the 12 people pick a random floor between 1 and 10
floors = [random.randint(1, 10) for _ in range(12)]
# count the number of unique floors the elevator must stop at
return len(set(floors))
# list of the number of floors the elevator stopped at for each trial
res = [simulate_trial() for _ in range(10_000)]
# compute the average, or expected number of floors the elevator needed to stop at over all 10,000 trials
print(sum(res) / len(res))