Dice sum probability

Write codeHard30 minCitadel and Goldman Sachs style

Your task

You roll a fair f-sided die (faces 1..f) exactly d times and sum the results. Return the probability, rounded to 6 decimal places, that the sum equals exactly the target. Constraints: 1 <= d <= 30, 2 <= f <= 30, target is any integer. Use a DP over (rolls, partial sum) accumulating counts, then divide by f**d.

Examples

dice_sum_probability(d: int, f: int, target: int) -> float
Example 1
Inputdice_sum_probability(2, 6, 7)
Output0.166667