1510. Stone Game IV Hard

@problem@discussion
#Math#Dynamic Programming#Game Theory



1/**
2 * [1510] Stone Game IV
3 *
4 * Alice and Bob take turns playing a game, with Alice starting first.
5 * Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.
6 * Also, if a player cannot make a move, he/she loses the game.
7 * Given a positive integer n, return true if and only if Alice wins the game otherwise return false, assuming both players play optimally.
8 *  
9 * Example 1:
10 * 
11 * Input: n = 1
12 * Output: true
13 * Explanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves.
14 * Example 2:
15 * 
16 * Input: n = 2
17 * Output: false
18 * Explanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0).
19 * 
20 * Example 3:
21 * 
22 * Input: n = 4
23 * Output: true
24 * Explanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0).
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= n <= 10^5
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/stone-game-iv/
35// discuss: https://leetcode.com/problems/stone-game-iv/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn winner_square_game(n: i32) -> bool {
41        false
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_1510() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.