Blindfold Nim
Time limit2sMemory limit512 MB
Each stack size is uniform on [0, a_i]; compute the probability that the first player wins a game of Nim with hidden positions where a player who overshoots a stack loses at once.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Combinatorics, Bit manipulation, Game theory
- Solved
- No attempts yet
Problem
Sprague and Grundy have been playing the game of Nim. They put stacks of coins on a table and move alternately. On each turn a player picks one stack and removes any positive number of coins from it. A player who cannot make a valid move loses.
They quickly worked out the optimal strategy, so now they want something more interesting: they decide to play blindfolded. All they know is that the initial number of coins in the -th stack is drawn uniformly at random from the integers in , every integer in that range being equally likely, and the stacks are drawn independently. A player loses immediately if he tries to take more coins from a stack than it currently holds. In particular, if a player is certain that every stack is empty, he must still move and therefore loses. Sprague moves first. Assuming both players play optimally and can see each other's moves, what is the probability that Sprague wins?
Input
The first line contains an integer (), the number of stacks. The second line contains positive integers . The sum of these integers does not exceed .
Output
Print a single real number: the probability that Sprague wins, rounded to exactly digits after the decimal point.