Question 21
A game of Nim is played with heaps that have stones (in other words, the -th heap has stones). The rules of Nim are not relevant to this problem. We only note that the first player wins if and only if the bitwise xor is non-zero.
Alice and Bob are playing the following game. Both Alice and Bob have several boxes with heaps. In the first phase they pick exactly one heap from each box. In the second phase Alice chooses some nonempty subset of those heaps, and the regular Nim game starts on chosen heaps with Bob to move first.
Bob already knows which heaps Alice picked. Our goal is to help him to perform his picks so that he wins the game no matter which heaps Alice chooses during the second phase.
For example, suppose Alice has picked two heaps with one and two stones, and Bob has two boxes:
- The first box has two heaps of sizes one and three stones.
- The second box has two heaps of sizes two and four stones.
Then notice that no matter what Bob picks, Alice can always pick a subset whose XOR sum is zero:
- If Bob picks 1,2, Alice picks 1,2,1,2 (1,1 or 2,2 would also work)
- If Bob picks 1,4, Alice picks 1,1
- If Bob picks 3,2, Alice picks 2,2
- If Bob picks 3,4, Alice picks 1,2,3
However suppose Alice has picked one heap with one stone, and Bob has two boxes:
- The first box has two heaps of sizes three and five stones.
- The second box has two heaps of sizes seven and four stones.
Then Bob can pick the heap with three stones from the first box and seven stones from the second, and no matter which non-empty subset of heaps Alice picks from , the XOR sum will be nonzero and Bob will win the game:
- ,
- ,
- and singleton subsets are already nonzero.
Assume that all heap sizes are positive integers between and .
Based on the above data, answer the given subquestions.
The solution that is sought by Bob can be viewed as the problem of finding a largest independent set in the: