Editorial for COCI '06 Contest 5 #5 Ivana
Submitting an official solution before solving the problem yourself is a bannable offence.
The task description doesn't explicitly state Zvonko's strategy, just that he tries to win when he can, i.e. looks for a sequence of moves that guarantees victory. One such strategy is to try to win with the largest score difference possible.
Zvonko does not know how well Ivana plays so part of his strategy is to assume she plays optimally as well, since he wants to be absolutely certain that he won't lose.
After Ivana's first move, the circle falls apart and we're left with a chain of numbers. The players alternate in taking numbers from the two ends of the chain (they get to pick which end to take off).
Suppose Ivana has made her first move and a chain of numbers is left. Let the largest score difference that the player currently up can achieve (this number can be negative if the player always loses), if what is left of the chain are numbers originally at indices to .
The current player either takes the number at index and leaves the opponent with the subproblem , or he takes the number at index and the opponent is left with the subproblem . The function can be efficiently calculated for all pairs of indices using dynamic programming.
The following identities hold:
- , if the number at index is odd, or if it is even
The solution has Ivana try each of the numbers as her first move and use the function to calculate if she has a winning strategy. The function can be calculated at once for all the chains, because the chains share many subproblems.
Comments