返回题库

放置或取走

Place or Take

专题
Probability / 概率
难度
L5

题目详情

你在玩一个单人游戏,面前有两个不透明盒子。每一轮你都可以选择“放入”或“取出”。“放入”表示由第三方向随机一个盒子中放入 $1;“取出”表示随机清空一个盒子,盒子里的钱归你所有。游戏一共进行 100 轮,每轮都必须二选一。若采取最优策略,这个游戏的期望收益是多少?

You are playing a one-player game with two opaque boxes. At each turn, you can choose to either "place" or "take". "Place" places $1 from a third party into one box randomly. "Take" empties out one box randomly and that money is yours. This game consists of 100 turns where you must either place or take. Assuming optimal play, what is the expected payoff of this game?

解析

设你连续“放入” NN 轮,然后在最后 100N100-N 轮执行“取出”。

这样你最终会拿到 NN,除非你倒霉到每次都从同一个盒子里取钱。在后一种情况下,你的期望只能拿到 N2\frac{N}{2}

因此,作为 NN 的函数,你的期望收益为:

N×(112100N)N \times (1 - \frac{1}{2^{100-N}})

可以做数值模拟,最优的 NN 大约是 94。

from scipy.optimize import minimize

func = lambda N: N * (1 - (1 / (2 ** (100-N))))
neg_func = lambda N: -func(N)

result = minimize(neg_func, 0, method='BFGS')

optimal_x = result.x[0]

print(f"Attained at x: {optimal_x}")

Original Explanation

Say you place for NN consecutive rounds and then take for the last 100N100-N

You will then collect NN, unless you are unlucky enough to take from the same box each time. In the latter case, you'd expect to get only N2\frac{N}{2}

Thus, as a function of NN, your expected gain is:

N×(112100N)N \times (1 - \frac{1}{2^{100-N}})

We can run a simulation to find the optimal value of N is ~94

from scipy.optimize import minimize

func = lambda N: N * (1 - (1 / (2 ** (100-N))))
neg_func = lambda N: -func(N)

result = minimize(neg_func, 0, method='BFGS')

optimal_x = result.x[0]

print(f"Attained at x: {optimal_x}")