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

Cover Up

Cover Up

"Цена правильная" - популярное игровое шоу, в котором участники играют в различные игры, чтобы выиграть сказочные призы. Одна из игр на шоу назывется “Прятки”, в которой следует угадать \textbf{5}-цифровое число (цену новой машины). Участникам предлагают два числа, из которых они должны выбрать первую цифру, три числа чтобы выбрать вторую цифру, и так далее. Участник выбирает по одному числу для каждой цифры (из множества еще не выбранных чисел для той цифры), после чего ему сообщают какие из них корректны; если хотя бы одна цифра правильная, участнику разрешают далее угадывать неверные цифры. Участники продолжают отгадывать, пока хотя бы одна из новых цифр является корректной. Игра заканчивается, либо когда все цифры отгаданы верно (игрок является победителем), либо после очередного хода ни одна из цифр не угадана правильно (проигрыш). Typically this game is not sheer luck. For example, suppose you had the following five possibilities for the last digit: \textbf{1}, \textbf{3}, \textbf{5}, \textbf{8} and \textbf{9}. Many car prices end with either a \textbf{5} or a \textbf{9}, so you might have, say, a \textbf{70}\% chance that one of these two numbers is correct; this breaks down to a \textbf{35}\% chance for either the 5 or the \textbf{9} and a \textbf{10}\% chance for each of the other three digits. Now say you pick the \textbf{5} and it’s wrong, but some other guess you made was right so you still get to play. With this additional information the probabilities for the remaining \textbf{4} numbers change: the probability for the \textbf{9} is now close to around \textbf{54}\%, while each of the other three numbers now has a little over a \textbf{15}\% chance. (We’ll let you figure out how we got these values). We’ll call the \textbf{5} and the \textbf{9} in the original group the known candidates, and typically there are known candidates in other columns as well. For example, if the two numbers for the first (high order) digit are \textbf{1} and \textbf{9}, the contestant can be \textbf{100}\% sure that the \textbf{1} is the correct digit (there aren’t too many \$\textbf{90,000} cars to be given away). For this problem, you are to determine the probability of winning the game if an optimal strategy for picking the numbers (based on probabilities such as those described above) is used. \InputFile Each test case will consist of two lines. The first will be \textit{\textbf{n}}, the number of digits in the number to be guessed. The maximum value of \textit{\textbf{n}} will be \textbf{5}. The second line will contain \textit{\textbf{n}} triplets of numbers of the form \textit{\textbf{m l p}} where \textit{\textbf{m}} is the number of choices for a digit, \textit{\textbf{l}} is the number of known candidates, and \textit{\textbf{p}} is the probability that one of the known candidates is correct. In all cases \textbf{0} ≤ \textit{\textbf{l}} < \textit{\textbf{m}} ≤ \textbf{10} and \textbf{0.0} ≤ \textit{\textbf{p}} ≤ \textbf{1.0}. Whenever \textit{\textbf{l}} = \textbf{0} (i.e., when there are no known candidates) \textit{\textbf{p}} will always be \textbf{0.0}. A line containing a single \textbf{0} will terminate the input. \OutputFile Output for each test case is the probability of winning using optimal strategy. All probabilities should be rounded to the nearest thousandth, and trailing \textbf{0}’s should not be output. (A \textbf{100}\% chance of winning should be output as \textbf{1}.)
Лимит времени 1 секунда
Лимит использования памяти 32 MiB
Входные данные #1
2
3 1 0.8 2 0 0.0
2
3 2 0.8 2 0 0.0
2
3 2 0.82 2 1 0.57
3
4 1 1.0 3 0 0.0 10 1 1.0
0
Выходные данные #1
0.850
0.600
0.644
1.000