[CodeFights] NumberGameVI
The problem is available here. A relatively straight forward game problem. If the current person want to win, the only requirement is that there exist a move can make B lose. And if there is no move can make B lose, then A will lose. Translate this into recursion and then we can have a working code. We can use a record table to hold whether we can win or not from the current state, using this memory to reduce the required recursion.
Similar Problem: Still two person A and B, they take values from a given list (all positive values) in turns. The first person who make the total sum above a given target can win.
Leave a Comment