If you are new to dynamic programming, then you should definetly try out this problem.
Problem
Problem description
Alice and Bob take turns playing a game, with Alice starting first.
Try it
Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:
Choosing any
XX
X with
0<X<n0 < X < n
0<X<n and
n%X==0n \% X == 0
n%X==0.
Replacing the number n on the chalkboard with n - x.
Also, if a player cannot make a move, they lose the game.
Return true if and only if Alice wins the game, assuming both players play optimally.
Example 1
Input: n = 2
Output: true
Explanation: Alice chooses 1, and Bob has no more moves.
Exmaple 2
Input: n = 3
Output: false
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
Constraints
1<=n<=10001 <= n <= 1000
1<=n<=1000
Top comments (0)