464. Can I Win Medium

@problem@discussion
#Math#Dynamic Programming#Bit Manipulation#Memoization#Game Theory#Bitmask



1/**
2 * [464] Can I Win
3 *
4 * In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.
5 * What if we change the game so that players cannot re-use integers?
6 * For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.
7 * Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally.
8 *  
9 * Example 1:
10 * 
11 * Input: maxChoosableInteger = 10, desiredTotal = 11
12 * Output: false
13 * Explanation:
14 * No matter which integer the first player choose, the first player will lose.
15 * The first player can choose an integer from 1 up to 10.
16 * If the first player choose 1, the second player can only choose integers from 2 up to 10.
17 * The second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.
18 * Same with other integers chosen by the first player, the second player will always win.
19 * 
20 * Example 2:
21 * 
22 * Input: maxChoosableInteger = 10, desiredTotal = 0
23 * Output: true
24 * 
25 * Example 3:
26 * 
27 * Input: maxChoosableInteger = 10, desiredTotal = 1
28 * Output: true
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= maxChoosableInteger <= 20
34 * 	0 <= desiredTotal <= 300
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/can-i-win/
40// discuss: https://leetcode.com/problems/can-i-win/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn can_i_win(max_choosable_integer: i32, desired_total: i32) -> bool {
46        false
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_464() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.