eolymp
bolt
Try our new interface for solving problems
Problems

Automat

Automat

Consider a device, which performs some work. Besides it must control its temperature. It must be neither too high nor too low. But something wrong has happened with the temperature controlling mechanisms, and now the device acts as follows. In each minute it selects one of possible actions of changing its temperatures and executes it. Each action is selected with the given probability, based on current temperature. The probabilities of temperature changes are given to you. Сount the probability of the event, that the temperature stays in the given range for a certain time. \InputFile First line of input contains the quantity of tests \textbf{T} (\textbf{1} ≤ \textbf{T} ≤ \textbf{20}). First line for each test contains numbers \textbf{A}, \textbf{B}, \textbf{C}, \textbf{N}, where \textbf{A} is the minimal allowed temperature, \textbf{B} is the maximal allowed temperature, \textbf{C} is the starting temperature, \textbf{N} is the device's working time in minutes. \textbf{0} ≤ \textbf{A} ≤ \textbf{B} ≤ \textbf{30}, \textbf{A} ≤ \textbf{C} ≤ \textbf{B}, \textbf{0} ≤ \textbf{N} ≤ \textbf{30}. Each of the next \textbf{B}--\textbf{A}+\textbf{1} lines contains \textbf{7} nonnegative integers, that sum up to \textbf{100} -- percentages of changes by \textbf{--4}, \textbf{--3}, \textbf{--2}, \textbf{--1}, \textbf{0}, \textbf{1} and \textbf{2} degrees correspondingly. \textbf{K}-th line (\textbf{1} ≤ \textbf{K} ≤ \textbf{B}--\textbf{A}+\textbf{1}) describes the probabilities for situation, when current temperature is equal to \textbf{A}+\textbf{K}--\textbf{1}. \OutputFile Output \textbf{T} lines of the form "\textbf{Case} #\textbf{A}: \textbf{B}", where \textbf{A} is the number of test (beginning from \textbf{1}), \textbf{B} is the desired probability for this test case. You must output the answer without rounding. It is guaranteed, that the answer has at most 60 decimal digits after the point.
Time limit 0.5 seconds
Memory limit 64 MiB
Input example #1
2
1 2 1 2
0 0 0 10 50 40 0
0 0 50 0 0 30 20
3 5 4 5
0 0 0 10 20 30 40
0 0 10 20 30 40 0
0 10 20 30 40 0 0
Output example #1
Case #1: 0.45
Case #2: 0.59049