New 21 Game Probability
Problem statement
A player starts with 0 points and repeatedly draws an integer uniformly at random from 1 through maxPts, inclusive. The player stops drawing as soon as the score is at least k.
Return the probability that the final score is at most n.
Function
new21Game(n: int, k: int, maxPts: int) → doubleExamples
Example 1
n = 10k = 1maxPts = 10return = 1.0Every possible first draw is at most 10.
Example 2
n = 6k = 1maxPts = 10return = 0.6Exactly six of the ten equally likely first draws finish at 6 or below.
Example 3
n = 21k = 17maxPts = 10return = 0.7327777870686082Dynamic programming accumulates the probability of every reachable stopping score from 17 through 21.
Constraints
0 <= k <= n <= 100001 <= maxPts <= 10000- The result is accepted with absolute tolerance
1e-9.