A player starts with 0 points and draws numbers while their total is below k. Each draw adds an integer chosen uniformly at random from 1 to max_pts, independently of all earlier draws. As soon as the total reaches k or more, the player stops drawing. Return the probability that the player's final total is at most n.
The report describes this round as a variant of a known probability task of this kind without saying what the variant changed; this version poses the base task.
Function Signature
def probability_at_most(n: int, k: int, max_pts: int) -> float:
Rules
-
If
k == 0
, the player never draws, the final total is 0, and the answer is
1.0
.
-
Return the probability as a floating-point number. An answer within an absolute error of
10^-5
of the exact probability is accepted.
Constraints
-
0 <= k <= n <= 10^4
-
1 <= max_pts <= 10^4
Examples
Example 1
Input: n = 10, k = 1, max_pts = 10
Output: 1.00000
The player draws once, and every possible total from 1 to 10 is at most 10.
Example 2
Input: n = 6, k = 1, max_pts = 10
Output: 0.60000
The player draws once, and 6 of the 10 equally likely totals are at most 6.
Example 3
Input: n = 21, k = 17, max_pts = 10
Output: 0.73278
The output shows the exact probability rounded to five decimal places.