837. New 21 Game Medium
1/**
2 * [837] New 21 Game
3 *
4 * Alice plays the following game, loosely based on the card game "21".
5 * Alice starts with 0 points and draws numbers while she has less than k points. During each draw, she gains an integer number of points randomly from the range [1, maxPts], where maxPts is an integer. Each draw is independent and the outcomes have equal probabilities.
6 * Alice stops drawing numbers when she gets k or more points.
7 * Return the probability that Alice has n or fewer points.
8 * Answers within 10^-5 of the actual answer are considered accepted.
9 *
10 * Example 1:
11 *
12 * Input: n = 10, k = 1, maxPts = 10
13 * Output: 1.00000
14 * Explanation: Alice gets a single card, then stops.
15 *
16 * Example 2:
17 *
18 * Input: n = 6, k = 1, maxPts = 10
19 * Output: 0.60000
20 * Explanation: Alice gets a single card, then stops.
21 * In 6 out of 10 possibilities, she is at or below 6 points.
22 *
23 * Example 3:
24 *
25 * Input: n = 21, k = 17, maxPts = 10
26 * Output: 0.73278
27 *
28 *
29 * Constraints:
30 *
31 * 0 <= k <= n <= 10^4
32 * 1 <= maxPts <= 10^4
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/new-21-game/
38// discuss: https://leetcode.com/problems/new-21-game/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn new21_game(n: i32, k: i32, max_pts: i32) -> f64 {
44 0f64
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_837() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.