题目叙述
方法:
期望DP
#include <bita/stdc++.h> const int maxn = 100010; double p[maxn], g[maxn], f[maxn]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%lf", p + i); for (int i = 1; i <= n; ++i) { g[i] = p[i] * (g[i - 1] + 1.f); f[i] = p[i] * (f[i - 1] + 2.f * g[i - 1] + 1.f) + (1.f - p[i]) * f[i - 1]; } printf("%.3lf ", f[n]); return 0; }