eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Cover Up

Cover Up

In the Price Is Right’s game Cover Up, players test their luck to win a new car. To win, the player must produce the actual retail price of the car from a board of possible numbers like: \includegraphics{https://static.e-olymp.com/content/5d/5db86ea38af468820d914f0912ba22d231bb3b44.jpg} The player selects one number from each column to form a \textit{bid}. Using the above board as an example, the first number in the price of the car is either \textbf{1} or \textbf{3}; the second is one of \textbf{9}, \textbf{4}, \textbf{2}; the third is one of \textbf{0}, \textbf{6}, \textbf{8}, \textbf{4}; and so on. Numbers may never move to a different column. After the player selects their bid, Drew Carey lights up the numbers in the bid which are correct. If the player has no numbers correct, the game ends and they lose; if they have at least one number correct, the game continues. When the game continues, the player is given another opportunity to select numbers from those columns that were incorrect. They will \textit{cover up} the wrong bid numbers with different selections from the same columns. Again, Drew Carey will light up any new correct digits. If the player has no \textit{new} numbers correct, the game ends and they lose; if they have at least one new number correct, the game continues. For example: \includegraphics{https://static.e-olymp.com/content/ac/acebdade476d8831b99e390c2d2e614b7071a630.jpg} The player selects an initial bid of \textbf{$14677}. The \textbf{1}, \textbf{4} and first \textbf{7} are correct (\textbf{c} stands for correct, \textbf{x} for incorrect, and \textbf{v} designates a column that requires a subsequent selection in the example above). The player covers up the incorrect \textbf{6} and \textbf{7} with an \textbf{8} and a \textbf{3} for a second bid of \textbf{$14873}. The \textbf{3} is correct, but the \textbf{8} is wrong. At this point it's a \textbf{50}/\textbf{50} chance. The player will select the \textbf{4} or the \textbf{0} and either win the car or lose the game. The show's sponsors would like to know how frequently their cars are given away. You are to use the assumption that players choose numbers uniformly from those remaining. \InputFile The sponsor will explore many variations, with prices up to 7 digits long. Therefore, the input file will begin with a line containing the integer \textbf{N ≤ 5000}, the number of test cases to be explored. The test cases follow. Each test case begins with the integer \textbf{d}, \textbf{0 < d ≤ 7}, the number of digits in the price of the car. \textbf{d} lines will follow, with non-empty strings of *distinct* digits in the range from \textbf{0} through \textbf{9}. Each of these lines represents a *column* of the digits in the game. The first line represents the leftmost column; the last the rightmost column. A \textbf{0} is possible as the first digit in the price of the car. \OutputFile Your program will print the probability of the player winning the car, rounded to \textbf{3} decimals.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
2
2
9
19
5
13
942
0684
34720
947368
Вихідні дані #1
1.000
0.321
Джерело Pacific North West Region Programming Contest, 2007