返回题库

十层楼

Ten Floor Building

专题
Probability / 概率
难度
L4

题目详情

一栋大楼的地下室以上有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 层楼分解为单独的楼层。

例如,设 S\textit{S} 为随机变量,表示电梯停在的楼层数。问题是要求 S\textit{S}E[S]\mathbb{E}[S] 的期望。然而,我们可以将S\textit{S}分解为10个指标随机变量的总和;我们将它们表示为 X1X10X_1 … X_{10}。每个 XiX_i 都是下限 i\textit{i} 的指示随机变量。详细来说,如果12个人中有一个在3楼下车,那么X3=1X_3 = 1。如果8楼无人下车,则X8=0X_8 = 0

然后这个问题简化为寻找 E[S]=E[X1++X10]=E[X1]++E[X10]\mathbb{E}[S] = \mathbb{E}[X_1 + … + X_{10}] = \mathbb{E}[X_1] + … + \mathbb{E}[X_{10}](通过期望线性)。我们现在需要计算 E[Xi],i[110]\mathbb{E}[X_i], \forall i \in [1 … 10]。然而,由于对称性(每个楼层与其他楼层无法区分并且具有相同的分布),我们可以简单地求解 E[Xi]\mathbb{E}[X_i] 以获得通用 i\textit{i}(并且 E[S]\mathbb{E}[S] 之和变为 10E[Xi]10*\mathbb{E}[X_i],因为所有 XiX_i 都是分布中的等效随机变量)。

指标随机变量的期望等于随机变量等于 1 的概率(该结论来自期望的定义)。所以问题就简化为寻找P(Xi=1)\mathbb{P}(X_i = 1)。口头上说,这是要求有人(至少 1 人)在 i\textit{i} 层下车的概率。

我们可以使用补码规则来求解这个表达式。 P(Xi=1)=1P(Xi=0)\mathbb{P}(X_i = 1) = 1 - \mathbb{P}(X_i = 0)P(Xi=0)\mathbb{P}(X_i = 0)i\textit{i} 层无人下车的概率。单人在 i\textit{i} 楼层不下车的概率为 910\frac{9}{10}(选择除 i\textit{i} 楼层外的任意楼层)。因此,由于所有 12 个人以相同的可能性且彼此独立地选择楼层,因此所有 12 个人选择不在楼层 i\textit{i} 下车的概率为 91012\frac{9}{10}^{12}

因此,P(Xi=1)=1P(Xi=0)=191012\mathbb{P}(X_i = 1) = 1 - \mathbb{P}(X_i = 0) = 1 - \frac{9}{10}^{12}。向上级联,这意味着 E[Xi]=191012\mathbb{E}[X_i] = 1 - \frac{9}{10}^{12}。这意味着 E[S]=10E[Xi]=10(191012)7.17\mathbb{E}[S] = 10 * \mathbb{E}[X_i] = 10 * (1 - \frac{9}{10}^{12}) \approx 7.17。因此,电梯预计将停在 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 S\textit{S} be the random variable indicating the number of floors the elevator stopped at. The question is asking for the expectation of S\textit{S}, or E[S]\mathbb{E}[S]. However, we can break down S\textit{S} into the sum of 10 indicator random variables; we’ll denote them X1X10X_1 … X_{10}. Each XiX_i is an indicator random variable for floor i\textit{i}. To elaborate, if one of the 12 people gets off on floor 3, then X3=1X_3 = 1. If nobody gets off on floor 8, then X8=0X_8 = 0.

This problem then reduces to finding the E[S]=E[X1++X10]=E[X1]++E[X10]\mathbb{E}[S] = \mathbb{E}[X_1 + … + X_{10}] = \mathbb{E}[X_1] + … + \mathbb{E}[X_{10}] (by Linearity of Expectation). We now need to compute the E[Xi],i[110]\mathbb{E}[X_i], \forall i \in [1 … 10]. However, due to symmetry (each floor is indistinguishable from the other and has identical distribution) we can simply solve for E[Xi]\mathbb{E}[X_i] for a generic i\textit{i} (and the sum E[S]\mathbb{E}[S] becomes 10E[Xi]10*\mathbb{E}[X_i] since all XiX_i 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 P(Xi=1)\mathbb{P}(X_i = 1). Stated verbally, this is asking for the probability that someone (at least 1) gets off at floor i\textit{i}.

We can solve for this expression using the complement rule. P(Xi=1)=1P(Xi=0)\mathbb{P}(X_i = 1) = 1 - \mathbb{P}(X_i = 0). P(Xi=0)\mathbb{P}(X_i = 0) is the probability that nobody gets off on floor i\textit{i}. The probability that a single person does not get off on floor i\textit{i} is 910\frac{9}{10} (he/she chooses any floor except floor i\textit{i}). 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 i\textit{i} is 91012\frac{9}{10}^{12}.

Therefore, P(Xi=1)=1P(Xi=0)=191012\mathbb{P}(X_i = 1) = 1 - \mathbb{P}(X_i = 0) = 1 - \frac{9}{10}^{12}. Cascading upwards, this means E[Xi]=191012\mathbb{E}[X_i] = 1 - \frac{9}{10}^{12}. And this means E[S]=10E[Xi]=10(191012)7.17\mathbb{E}[S] = 10 * \mathbb{E}[X_i] = 10 * (1 - \frac{9}{10}^{12}) \approx 7.17. 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))