返回题库

最大化产品

Maximize the Product

专题
Probability / 概率
难度
L4

第 1 小问

题目详情

假设你掷出两个公平的 6 面骰子。两个骰子的乘积的期望值是多少?

Suppose you roll two fair 6-sided dice. What is the expected value of the product of the two dice?

解析

E[D1]=E[D2]=1+2+3+4+5+66=3.5E[D1] = E[D2] = \frac{1+2+3+4+5+6}6 = 3.5 由于两个卷是独立的,因此产品的期望值是期望值的乘积: E[D1D2]=3.53.5=12.25E[D1\cdot{D2}] = 3.5 \cdot 3.5 = 12.25


Original Explanation

E[D1]=E[D2]=1+2+3+4+5+66=3.5E[D1] = E[D2] = \frac{1+2+3+4+5+6}6 = 3.5

Since the two rolls are independent, the expected value of the product is the product of the expected values:

E[D1D2]=3.53.5=12.25E[D1\cdot{D2}] = 3.5 \cdot 3.5 = 12.25

第 2 小问

题目详情

假设你有两个公平的 6 面骰子,并且你正在尝试通过可选的重掷来最大化产品。最佳游戏的预期值是多少?

Suppose you have the two fair 6-sided dice and you are trying to maximize the product with an optional re-roll. What is the expected value with optimal play?

解析

假设 D1D1 是具有较高值的骰子。在最佳玩法下,我们永远不会重新掷两个骰子中的最大值。为了找到最大值的预期值,让我们计算一个值可能成为最大值的方式的数量。对于 11,你必须掷出两个 1s1's。对于 2 作为你的最大值,你只能滚动 112s2's,这为你提供了 2212\cdot2 -1 方法。 (这包括 (1,1)(1,1) 情况,因此减去以避免重复计数)继续此过程以获得: E[D1]=1(1)+3(2)+5(3)+7(4)+9(5)+11(6)36=16136E[D1] = \frac{ 1(1) + 3(2) + 5(3) + 7(4) + 9(5) + 11(6) }{36} = \frac{161}{36} 然后我们可以使用类似的计算来获得 D2D2 的期望值,即最小值。然而,如果 D2D2 低于重新掷骰的预期值,我们会用 3.53.5 替换该值。因此, E[D2]=27(3.5)+5(4)+3(5)+1(6)36=27172E[D2] = \frac{ 27(3.5) + 5(4) + 3(5) + 1(6) }{36} = \frac{271}{72} 因为这些骰子彼此独立,所以我们可以将期望相乘,得到: E[D1D2]=1613627172=43631259216.83E[D1\cdot{D2}] = {\frac{161}{36}} \cdot \frac{271}{72}= \frac{43631}{2592} \simeq 16.83

import random
from typing import Callable

roll_dice: Callable[[None], int] = lambda: random.randrange(1, 7)

products = []

for i in range(1000000):

    d1 = roll_dice()
    d2 = roll_dice()

    product = d1 * d2

    if min(d1, d2) < 3.5:
        reroll = roll_dice()
        product = max(d1, d2) * reroll

    products.append(product)

#expecting something close to 16.83
print(sum(products) / len(products))

Original Explanation

Suppose D1D1 is the die with the higher value. With optimal play, we would never re-roll the maximum of the two dice. To find the expected value of the maximum, let's count the number of ways a value could be a maximum. For 11, you must roll two 1s1's. For 2 to be your maximum, you can only roll 11's and 2s2's which gives you 2212\cdot2 -1 ways. (This includes (1,1)(1,1) case so subtract to not double count) Continue this process to get:

E[D1]=1(1)+3(2)+5(3)+7(4)+9(5)+11(6)36=16136E[D1] = \frac{ 1(1) + 3(2) + 5(3) + 7(4) + 9(5) + 11(6) }{36} = \frac{161}{36}

We can then use a similar computation to get the expected value of D2D2, the minimum. However, in the case the D2D2 is below the expected value of a re-roll, we replace that value with the 3.53.5. Thus,

E[D2]=27(3.5)+5(4)+3(5)+1(6)36=27172E[D2] = \frac{ 27(3.5) + 5(4) + 3(5) + 1(6) }{36} = \frac{271}{72}

Because these die rolls were indendent of each other, we can multiply the expectations resulting in:

E[D1D2]=1613627172=43631259216.83E[D1\cdot{D2}] = {\frac{161}{36}} \cdot \frac{271}{72}= \frac{43631}{2592} \simeq 16.83
import random
from typing import Callable

roll_dice: Callable[[None], int] = lambda: random.randrange(1, 7)

products = []

for i in range(1000000):

    d1 = roll_dice()
    d2 = roll_dice()

    product = d1 * d2

    if min(d1, d2) < 3.5:
        reroll = roll_dice()
        product = max(d1, d2) * reroll

    products.append(product)

#expecting something close to 16.83
print(sum(products) / len(products))