#P5516. [MtOI2019] 小铃的烦恼
[MtOI2019] 小铃的烦恼
Background
In Gensokyo, Motoori Kosuzu not only often gets bumped into by others, but also has to organize the books in Suzunaan. She has many troubles.
Problem Description
Kosuzu organizes the books in Suzunaan once every day. This time there are magic books on the table, placed in a row. Each book has a magic attribute and an index.
At the beginning, all books had the same magic attribute. However, after being used many times, their magic attributes changed. Kosuzu wants all books to have the same magic attribute again.
This time Kosuzu asks Kirisame Marisa for help. Each time, Marisa can cast a chosen spell, and the spell will randomly choose two books (where is not equal to ).
After these two books are chosen, Marisa casts a transfer spell: with probability , the magic attribute of book becomes the magic attribute of book . That is, with probability , even if you have chosen books , the transfer fails, meaning this operation is invalid.
Note that is the probability that the transfer succeeds, and it does not affect the random process of choosing the two books.
Now Kosuzu wants to know: what is the expected number of operations needed to make the magic attributes of all books identical? Since time is tight, Kosuzu asks you for help. Otherwise, she will not give you the points for this problem.
Input Format
The first line contains a string. The -th character represents the magic attribute of the -th book. Note that each book’s magic attribute is any uppercase letter from to . (Let the length of the string be .)
Lines to each contain real numbers. The -th number on the -th of these lines represents .
Output Format
Output the answer, accurate to digit after the decimal point.
NACLYFISHAKIOI
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
164.9
DSGAY
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0 1.0
16.0
Hint
For the first of the testdata, , and there is at most one kind of magic attribute.
For another of the testdata, , and there are at most two kinds of magic attributes, and the count of one of the attributes is at most .
For of the testdata, .
For all testdata, $\left(\sum\limits_{a=1}^{n}\sum\limits_{b=1}^{n}p_{a,b}\right) = n^2$.
Source
Meituzhijia 2019 League (MtOI2019) T3
Problem setter: Qiuly
Translated by ChatGPT 5