# 两个有趣的概率问题

P(k)=C(k1m1)C(mn)

E(Max)=k=mnP(k)k=k=mnmC(mk)C(mn)

k=mnC(mk)=C(m+1n+1)

E(Max)=mC(m+1n+1)C(mn)=m(n+1)/(m+1)

def simulation_notrepeat(n,m):
tot_average = 0
for i in range(10000):
max = 0
count = 0
is_repeated = set([])
while count < m:
x = random.randint(1,n)
if x not in is_repeated:
count += 1
if x > max:
max = x
tot_average += max
print(tot_average/10000)
def test_notrepeat(n,m):
print(m*(n+1)/(m+1))

P(k)=km(k1)mnm

E(Max)=k=1nP(k)k

import random
def simulation(n,m):
tot_average = 0
for i in range(10000):
max = 0
for j in range(m):
x = random.randint(1,n)
if x > max:
max = x
tot_average += max
print(tot_average/10000)
def test_math(n,m):
average = 0
for k in range(1,n+1):
average += (k**m - ((k-1)**m))*k
print(average/(n**m))
def test_notrepeat(n,m):
print(m*(n+1)/(m+1))
def test(n,m,simulation,test_math):
simulation(n,m)
test_math(n,m)
test(100,35,simulation,test_math)
test(100,35,simulation_notrepeat,test_notrepeat)

• 本文已收录于以下专栏：

举报原因： 您举报文章：两个有趣的概率问题 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)