PDD 第三题
PDD 第三题,简单来说就是每次把之前所有的色子当作一个色子,然后摇了新的之后更新这个色子,分三种情况讨论就行了。 from copy import deepcopy import sys _ = sys.stdin.readline() line = sys.stdin.readline().strip().split(" ") nums = list(map(int, line)) before = dict() for i in range(1, nums[0]+1): before[i] = 1/nums[0] for i in nums[1:]: after = deepcopy(before) for j in range(1, i+1): if j not in before: after[j] = 1/i continue p1 = before[j] * 1/i p2_left = 0 for k in range(1, j): p2_left += before[k] p2 = p2_left * 1/i p3 = before[j] * (j-1)/i after[j] = p1+p2+p3 before = after result = 0 for k in before: result += before[k] * k print("%.2f" % result
#笔试题目##拼多多##题解#