|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|5 초||256 MB||24||6||5||22.727%|
There are several events that are about to happen. Each event has either a positive outcome or a negative outcome, and these outcomes affect the probabilities of the outcomes of subsequent events.
The events occur in the order given in the input. For every event i, there is an associated integer-valued base value, which we denote by bi. To decide the outcome of an event, we roll a fair m-sided die with sides marked 1 through m and add the amount shown on the die to the base value. If the result is strictly positive, then the outcome is positive; otherwise (including if the result is zero), the negative outcome occurs. If the positive outcome occurs, then we modify the base values of all subsequent events according to a list of modifiers associated with the event. That is, if the outcome of event i is positive, the new base value for event j is bj + pij, where pij is the modifier to event j in the case of a positive outcome for event i. If the negative outcome occurs, we do the same but with a different list of modifiers; the base value for event j becomes bj + qij, where qij is the associated modifier.
You have the power to intervene in a certain number of events. When you intervene, instead of rolling one die, you roll two dice and then choose the die you prefer. For each event, you decide whether or not to intervene immediately before that event’s die is rolled, i.e., you may use the outcomes of previous events to decide whether or not to intervene. Can you maximize the probability of the final event having a positive outcome?
The first line contains three space-separated integers n, k, and m (1 ≤ k ≤ n ≤ 20, 4 ≤ m ≤ 1,000), denoting the number of events, the maximum number of interventions, and the die size, respectively. Next are 3n lines describing the base values and modifiers of the events, in the following format:
The final event has no modifiers, and thus the last two lines of the input are empty.
Print, on a single line, a single number equal to the maximum probability of the final event having a positive outcome, rounded and displayed to exactly 6 decimal places.
2 2 6 -3 -100 100 0
4 1 10 -5 -10 9 0 9 -10 0 -10 0 10 0 0 -10 10 0 -10