|
发表于 2020-1-28 21:38:54
|
显示全部楼层
版主:这个题计算是浮点数,不同的算法结果可能有一点点差别,希望您能用软判决 比如 0.199999992和 0.199999993之类的是有可能出现的
- def fun317(w,r):
- def inner(w,r):
- if (w,r) in dictionary:
- return dictionary[(w,r)]
- else:
- if w > 1 and r > 0:
- res = 0
- res += (w/(w+r))*((w-1)/(w+r-1))*inner(w-2,r)
- res += (w/(w+r))*(r/(w+r-1))*inner(w-1,r-1)
- res += (r/(w+r))*(w/(w+r))*inner(w-1,r)
- res += (r/(w+r))*(r/(w+r))*inner(w,r-1)
- dictionary[(w,r)] = res
- elif w==0 and r > 0:
- dictionary[(w,r)] = 0
- elif w==1 and r > 0:
- dictionary[(w,r)] = (1/(1+r))**2
- else:
- dictionary[(w,r)] = 1
- return dictionary[(w,r)]
- dictionary = dict()
- return inner(w,r)
复制代码
|
评分
-
查看全部评分
|