# 2. 题解

$g _ x=p _ x \times (g _ {x – 1} + 1)$

$p _ x$表示在 $x$这个位置打出 1 的概率

$\Delta = E[(l + 1) ^ 2] – E(l)$
$=E[(l + 1) ^ 2 – l]$
$=E(l ^ 2 + 2l + 1 – l)$
$=E(l ^ 2 + l + 1)$
$=E(l ^ 2) + E(l) + 1$

$E[(l + 1) ^ 2] = E(l ^ 2) + 2 E(l) + 1$

$h _ x = p _ x \times (h _ {x – 1} + 2 g _ {x – 1} + 1)$

$\Delta = E[(l + 1) ^ 3] – E(l ^ 2)$
$=E[(l + 1) ^ 3 – l ^ 2]$
$=E(l ^ 3 + 3 l ^ 2 + 3 l + 1 – l ^ 2)$
$=E(l ^ 3 + 2l ^ 2 + 3 l + 1)$
$=E(l ^ 3) + 2 E(l ^ 2) + 3 E(l) + 1$

$E[(l + 1) ^ 3] = E(l ^ 3) + 3 E(l ^ 2) + 3 E(l) + 1$

$f _ x = p _ x \times (f _ {x – 1} + 3 h _ {x – 1} + 3 g _ {x – 1} + 1)$

（另外还有简化版的这一题，参见 Easy BZOJ – 3450

（另另外还有简化版的这一题，参见 CF235B Let’s Play Osu!

#include <bits/stdc++.h>

#define NS (100005)

using namespace std;

int n;

double p[NS], g[NS], h[NS], f[NS];

int main(int argc, char const* argv[])
{
scanf("%d", &n);
for (int i = 1; i <= n; i += 1) scanf("%lf", &p[i]);
for (int i = 1; i <= n; i += 1)
{
g[i] = p[i] * (g[i - 1] + 1);
h[i] = p[i] * (h[i - 1] + 2 * g[i - 1] + 1);
f[i] = p[i] * (f[i - 1] + 3 * h[i - 1] + 3 * g[i - 1] + 1)
+(1 - p[i]) * f[i - 1];
}
printf("%.1f\n", f[n]);
return 0;
}