首先根据题设直接设期望: $ E(G(x))$ 表示到x
的期望得分.
因为:
\[ E(x + \Delta) = E(x) + E(\Delta) \]
并且期望的本质实际上是积分, 所以我们只要计算每一个点对应的增量\(\Delta\)就可以计算当前的期望值.
发现\(E(x ^ 3)\) 的增量为\(3E(x ^ 2) + 3E(x) + 1\)
\(E(x ^ 2)\)的增量为\(2E(x) + 1\)
然后直接dp计算即可.
Code
#include<bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i) #define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i) #define clar(a, b) memset((a), (b), sizeof(a)) #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long LL; typedef long double LD; int read() { char ch = getchar(); int x = 0, flag = 1; for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1; for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; return x * flag; } void write(int x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + 48); } const int Maxn = 100009; int n; double f[Maxn]; double Expection[Maxn][4]; double g[Maxn]; void init() { n = read(); rep (i, 1, n) scanf("%lf", &f[i]); } void solve() { rep (i, 1, n) { Expection[i][1] = (Expection[i - 1][1] + 1) * f[i]; Expection[i][2] = (Expection[i - 1][2] + 2 * Expection[i - 1][1] + 1) * f[i]; Expection[i][3] = Expection[i - 1][3] + (3 * Expection[i - 1][2] + 3 * Expection[i - 1][1] + 1) * f[i]; } printf("%.1lf\n", Expection[n][3]); } int main() { freopen("BZOJ4318.in", "r", stdin); freopen("BZOJ4318.out", "w", stdout); init(); solve(); #ifdef Qrsikno debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC); #endif return 0; }