|  | 
|  | 1 | +<h2><a href="https://leetcode.com/problems/new-21-game">New 21 Game</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>Alice plays the following game, loosely based on the card game <strong>"21"</strong>.</p> | 
|  | 2 | + | 
|  | 3 | +<p>Alice starts with <code>0</code> points and draws numbers while she has less than <code>k</code> points. During each draw, she gains an integer number of points randomly from the range <code>[1, maxPts]</code>, where <code>maxPts</code> is an integer. Each draw is independent and the outcomes have equal probabilities.</p> | 
|  | 4 | + | 
|  | 5 | +<p>Alice stops drawing numbers when she gets <code>k</code> <strong>or more points</strong>.</p> | 
|  | 6 | + | 
|  | 7 | +<p>Return the probability that Alice has <code>n</code> or fewer points.</p> | 
|  | 8 | + | 
|  | 9 | +<p>Answers within <code>10<sup>-5</sup></code> of the actual answer are considered accepted.</p> | 
|  | 10 | + | 
|  | 11 | +<p> </p> | 
|  | 12 | +<p><strong class="example">Example 1:</strong></p> | 
|  | 13 | + | 
|  | 14 | +<pre> | 
|  | 15 | +<strong>Input:</strong> n = 10, k = 1, maxPts = 10 | 
|  | 16 | +<strong>Output:</strong> 1.00000 | 
|  | 17 | +<strong>Explanation:</strong> Alice gets a single card, then stops. | 
|  | 18 | +</pre> | 
|  | 19 | + | 
|  | 20 | +<p><strong class="example">Example 2:</strong></p> | 
|  | 21 | + | 
|  | 22 | +<pre> | 
|  | 23 | +<strong>Input:</strong> n = 6, k = 1, maxPts = 10 | 
|  | 24 | +<strong>Output:</strong> 0.60000 | 
|  | 25 | +<strong>Explanation:</strong> Alice gets a single card, then stops. | 
|  | 26 | +In 6 out of 10 possibilities, she is at or below 6 points. | 
|  | 27 | +</pre> | 
|  | 28 | + | 
|  | 29 | +<p><strong class="example">Example 3:</strong></p> | 
|  | 30 | + | 
|  | 31 | +<pre> | 
|  | 32 | +<strong>Input:</strong> n = 21, k = 17, maxPts = 10 | 
|  | 33 | +<strong>Output:</strong> 0.73278 | 
|  | 34 | +</pre> | 
|  | 35 | + | 
|  | 36 | +<p> </p> | 
|  | 37 | +<p><strong>Constraints:</strong></p> | 
|  | 38 | + | 
|  | 39 | +<ul> | 
|  | 40 | +	<li><code>0 <= k <= n <= 10<sup>4</sup></code></li> | 
|  | 41 | +	<li><code>1 <= maxPts <= 10<sup>4</sup></code></li> | 
|  | 42 | +</ul> | 
0 commit comments