One Hundred Prisoners and One Hundred Boxes
题目
One hundred prisoners are numbered 1 to 100. In a room are 100 closed boxes, and inside them, in random order, are slips bearing the numbers 1 to 100.
Each prisoner enters alone, may open at most 50 boxes, and must find the slip bearing their own number. Boxes are closed again afterwards and no communication is allowed once the process begins. All prisoners must succeed or all are executed.
They may agree a strategy beforehand. Find a strategy that succeeds with probability greater than 30%.
解析
先自己试一试,卡住了再打开提示。
查看解析
The naive baseline. If each prisoner opens 50 boxes at random, each succeeds with probability , and all succeed with probability .
The strategy. Prisoner opens box first. Whatever number is on the slip inside, they open that box next, and keep following the slips, up to 50 boxes.
Step 1: The slips form loops. Draw an arrow from each box to the box named by the slip inside it. Every box has exactly one arrow going out (its own slip) and exactly one coming in (exactly one slip names it). So the arrows split the boxes into closed loops.
Step 2: Why this helps. Prisoner starts at box and walks around the loop that contains box . Slip is in the box whose arrow points back to box , which is the last box of the loop. So prisoner finds their slip after exactly as many boxes as the loop has. That means:
- prisoner succeeds exactly when the loop through box has at most boxes;
- everyone succeeds exactly when no loop has more than boxes.
Step 3: Count the arrangements with a long loop. All ways of putting the slips in the boxes are equally likely. Fix a length between and . Every arrangement with a loop of exactly boxes can be built in three steps:
- Choose which boxes are in the long loop: ways. This is just picking a set of boxes out of ; the order comes in the next step.
- Join those boxes into one loop: ways. Start from the smallest box in the set. The other boxes can follow it in any order, and each order is a different loop. Once the loop is fixed, so are the slips in these boxes: each box holds the number of the next box.
- Fill the other boxes with the other slips in any way: ways.
No arrangement is counted twice, because two loops longer than would need more than boxes. Multiplying, and using :
Dividing by the arrangements in total:
Check on a small case: with boxes and a loop of , the steps give , and .
Step 4: The probability. At most one loop can be longer than , so these events for different never happen together, and we can add them:
Answer:
just over 31%.
With more prisoners, prisoners each opening boxes, the sum approaches . So the chance of survival only falls to , even with a million prisoners.
Why interviewers like it. Random guessing makes the prisoners succeed or fail independently. Following the loops ties their fates together, so everyone succeeds on the same event: no long loop.