我认为 会 增加选中汽车的机会。
设总共有N扇门,其中某一扇门后面有车。
策略一:我选择某扇门,在主持人提示之后,不变更选择。
实质:决定我中奖的,是“我一次选中了有车的门”这一事件A,与后续事件无关。
事件概率/中奖概率:
中奖概率:
比较上述情况可知:;
即变更选择是更优策略。
举例:
设N=3,依据上述公式,策略一中奖的概率是0.333,策略二是0.667;
设N=5,依据上述公式,策略一中奖的概率是0.200,策略二是0.267;
import random
def monte(N=3, rechoose=False):
    # Setup scenary.
    doors = list(range(N))
    reward = random.choice(doors)
    # My choice.
    mychoi = random.choice(doors)
    # The host‘s possible hint, excluding
    # - my choice
    # - the reward.
    tdoors = doors[:]
    tdoors.remove(mychoi)
    if reward != mychoi:
        tdoors.remove(reward)
    tempta = random.choice(tdoors)
    # My second choice, excluding
    # - the first choice
    # - the host‘s temptation
    if rechoose:
        doors.remove(mychoi)
        doors.remove(tempta)
        mychoi = random.choice(doors)
    return reward == mychoi
测试运行结果。
T = 100000 # 例一 In [1]: sum(monte(N=3) for _ in range(T)) / T Out[1]: 0.332977 In [2]: sum(monte(N=3,rechoose=True) for _ in range(T)) / T Out[2]: 0.667285 # 例二 In [3]: sum(monte(N=5) for _ in range(T)) / T Out[3]: 0.200164 In [4]: sum(monte(N=5,rechoose=True) for _ in range(T)) / T Out[4]: 0.266301
原文:http://www.cnblogs.com/chenweijava/p/6670969.html