Merging Cells
Time limit2sMemory limit1024 MB
Given N cells in a row with sizes, adjacent cells merge at random until one remains, and the task is to find the probability each original label ends as the winner modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Divide and conquer, Probability
- Solved
- No attempts yet
Problem
Bessie is playing an online game with a row of cells. Each cell has a label and a size. Cells keep eating their neighbors until only one winner remains.
There are cells () in a row, labeled to from left to right. The initial sizes are ().
While more than one cell remains, a pair of adjacent cells is picked uniformly at random and merged into one new cell. Suppose a cell with label and current size merges with a cell with label and current size . The new cell has size . Its label is the label of the larger cell. If the sizes are equal, the larger label wins. Formally,
For each label from to , find the probability that the final cell has label . The probability can be written as with . Print .
Input
The first line contains .
The next line contains .
Output
For each label from to , print on its own line the probability that the final cell has label , modulo .