P16288 [Lanqiao Cup 2026 NOI Qualifier Python/Java Group A] Magic Dice

Description

Xiao Lan wants to use a 6-sided magic dice to test his luck. When rolling this dice, the probabilities that the top face is $1,2,3,4,5,6$ are $p_1, p_2, p_3, p_4, p_5, p_6$, respectively. Xiao Lan will roll this dice $n$ times in a row and record the result of each roll. Let $L$ be the maximum length of consecutive occurrences of the number $6$ among these $n$ results. Now, please help Xiao Lan compute the mathematical expectation of $L$. Note: The expectation of $L$ only depends on the probability $p_6$ of getting $6$. The other probabilities $p_1,\dots,p_5$ are only used to ensure the probability distribution of the dice is complete.

Input Format

The input has two lines. The first line contains a positive integer $n$, representing the number of rolls. The second line contains $6$ floating-point numbers $p_1, p_2, p_3, p_4, p_5, p_6$ separated by spaces, representing the probabilities that the top face is $1,2,3,4,5,6$, respectively.

Output Format

Output a floating-point number, representing the mathematical expectation of $L$. Round the result to two decimal places.

Explanation/Hint

### Constraints and Notes For $30\%$ of the testdata, $1 \leq n \leq 8$. For all testdata, $1 \leq n \leq 500$, $\sum_{i=1}^{6} p_i = 1$, and $p_i \in [0, 1]$. The Luogu testdata guarantees that each $p_i$ has at most $6$ digits after the decimal point, and there will be no extreme constructions that “break precision”. Translated by ChatGPT 5