Given a colored board of at most 17 cells, simulate rabbits that move, collide, and shrink the board, then compute the expected number left from a uniformly random start.
Medium6SimulationCombinatoricsProbabilityImplementationNo attempts yetTime limit2sMemory limit512 MBRabbits gather to play a game.
The game is played on N cells (N≥2) placed in a row. The cells are numbered from 0 to N−1 from left to right, and each cell is painted white, black, or red.
r rabbits start the game, each on a different cell. The set of starting cells is one of the ways to choose r distinct cells, and every such way is equally likely.
The size of the board is the number of cells still on it, and it starts at N. While the size of the board is greater than 2, the following steps repeat.
When the game ends, the board holds 0, 1, or 2 rabbits. Compute the expected number of rabbits left on the board.
The first line contains the colors of the board as a string. W is white, B is black, and R is red, and the length of the string is the number of cells N. 2≤N≤17.
The second line contains the number of rabbits r (1≤r≤N).
Print the expected number of remaining rabbits as a reduced fraction on one line. The format is p/q, with q≥1 and the greatest common divisor of p and q equal to 1. If the expected value is an integer, write 1 as the denominator. For example, print 0/1 for an expected value of 0, and 2/1 for an expected value of 2.