Codeforces Round 146 (Div. 1)
B
Let's Play Osu!
Codeforces
2000
原题
← AC →
翻译中…

You're playing a game called Osu! Here's a simplified version of it. There are $*n*$ clicks in a game. For each click there are two outcomes: correct or bad. Let us denote correct as "O", bad as "X", then the whole play can be encoded as a sequence of $*n*$ characters "O" and "X".

翻译中…

Using the play sequence you can calculate the score for the play as follows: for every maximal consecutive "O"s block, add the square of its length (the number of characters "O") to the score. For example, if your play can be encoded as "OOXOOOXXOO", then there's three maximal consecutive "O"s block "OO", "OOO", "OO", so your score will be $2^{2} + 3^{2} + 2^{2} = 17$. If there are no correct clicks in a play then the score for the play equals to $0$.

翻译中…

You know that the probability to click the $*i*$-th $(1 ≤ *i* ≤ *n*)$ click correctly is $*p*_{*i*}$. In other words, the $*i*$-th character in the play sequence has $*p*_{*i*}$ probability to be "O", $1 - *p*_{*i*}$ to be "X". You task is to calculate the expected score for your play.

翻译中…

Input

翻译中…

The first line contains an integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the number of clicks. The second line contains $*n*$ space-separated real numbers $*p*_{1}, *p*_{2}, ..., *p*_{*n*}$ $(0 ≤ *p*_{*i*} ≤ 1)$.

翻译中…

There will be at most six digits after the decimal point in the given $*p*_{*i*}$.

翻译中…

Output

翻译中…

Print a single real number — the expected score for your play. Your answer will be considered correct if its absolute or relative error does not exceed $10^{ - 6}$.

翻译中…

Note

翻译中…

For the first example. There are 8 possible outcomes. Each has a probability of 0.125.

翻译中…
  • "OOO" $→$ $3^{2} = 9$;
  • "OOX" $→$ $2^{2} = 4$;
  • "OXO" $→$ $1^{2} + 1^{2} = 2$;
  • "OXX" $→$ $1^{2} = 1$;
  • "XOO" $→$ $2^{2} = 4$;
  • "XOX" $→$ $1^{2} = 1$;
  • "XXO" $→$ $1^{2} = 1$;
  • "XXX" $→$ $0$.
翻译中…

So the expected score is image

翻译中…

样例

Input #1
3
0.5 0.5 0.5
Output #1
2.750000000000000
InputCopy OutputCopy
Input #2
4
0.7 0.2 0.1 0.9
Output #2
2.489200000000000
InputCopy OutputCopy
Input #3
5
1 1 1 1 1
Output #3
25.000000000000000
InputCopy OutputCopy
题目信息
题号
235B
时间限制
2 s
内存限制
256 MB
标签
动态规划
数学
概率论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。