Expected Repaints for Balls
Time limit2sMemory limit128 MB
Given N colored balls, compute the expected number of random repaint operations needed until all balls share one color.
- Level
Hard8 of 10
- Topics
- Probability, Dynamic programming, Math, Combinatorics
- Solved
- No attempts yet
Problem
Sejun has a bag containing N colored balls. One operation works as follows. First, he chooses one ball from the bag, then chooses a different ball from the bag. He repaints the second ball so that it has the same color as the first ball. After the paint dries, he puts both balls back into the bag and mixes them.
Find the expected number of repaint operations needed until all balls have the same color.
Input
The first line contains the number of balls N. (1 ≤ N ≤ 24)
The second line contains a string of length N describing the colors of the balls. The string has no spaces, and each character is one uppercase English letter from A to Z.
Output
Print the expected number of repaint operations needed until all balls have the same color.
Your answer is accepted if its absolute or relative error is at most 10^-8.