2
def getProbability(self, balls: List[int]) -> float:9
prefix[i] = prefix[i - 1] + balls[i]11
# STEP 1: Compute the number of ways to pick j balls from i total, i.e. C(i, j)12
choose = [[0] * (N + 1) for i in range(N + 1)]14
for i in range(1, N + 1):15
for pick in range(N + 1):16
# DECISION 1: don't pick the ith ball17
choose[i][pick] += choose[i - 1][pick]18
# DECISION 2: pick the ith ball19
choose[i][pick] += choose[i - 1][pick - 1]21
# STEP 2: From first i ball types, compute ways to:22
# - pick c1 balls in box123
# - such that the difference in unique ball count between box1 and box2 is d24
ways = [[defaultdict(int) for k in range(n + 1)] for i in range(m + 1)]32
prev_total = prefix[i - 1]33
for c1 in range(n + 1):38
for add1 in range(b + 1):50
ways_to_add = choose[b][add1] * ways[i][c1][d]51
ways[i + 1][c1 + add1][d + delta] += ways_to_add53
# compute the actual probability54
return ways[m][n][0] / choose[N][n]