Package g0801_0900.s0837_new_21_game
Class Solution
java.lang.Object
g0801_0900.s0837_new_21_game.Solution
837 - New 21 Game.<p>Medium</p>
<p>Alice plays the following game, loosely based on the card game <strong>“21”</strong>.</p>
<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>
<p>Alice stops drawing numbers when she gets <code>k</code> <strong>or more points</strong>.</p>
<p>Return the probability that Alice has <code>n</code> or fewer points.</p>
<p>Answers within <code>10<sup>-5</sup></code> of the actual answer are considered accepted.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 10, k = 1, maxPts = 10</p>
<p><strong>Output:</strong> 1.00000</p>
<p><strong>Explanation:</strong> Alice gets a single card, then stops.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 6, k = 1, maxPts = 10</p>
<p><strong>Output:</strong> 0.60000</p>
<p><strong>Explanation:</strong> Alice gets a single card, then stops. In 6 out of 10 possibilities, she is at or below 6 points.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 21, k = 17, maxPts = 10</p>
<p><strong>Output:</strong> 0.73278</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= k <= n <= 10<sup>4</sup></code></li>
<li><code>1 <= maxPts <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
new21Game
public double new21Game(int n, int k, int w)
-