1、题意:一个序列,连续的一段1对得分具有x3贡献,那么问期望得分
2、分析:一道裸的期望dp,那么新加入一个1,对答案的贡献为x3?(x?1)3=3x2+3x+1 直接暴力算出期望的平方和期望,每次dp的时候更新一下就好了
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 1000010
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < ‘0‘ || ch > ‘9‘){
if(ch == ‘-‘) f = -1;
ch = getchar();
}
while(‘0‘ <= ch && ch <= ‘9‘){
x = x * 10 + ch - ‘0‘;
ch = getchar();
}
return x * f;
}
double l[M], l2[M], f[M];
int main(){
int n = read();
for(int i = 1; i <= n; i ++){
double x; scanf("%lf", &x);
l[i] = (l[i - 1] + 1) * x;
l2[i] = (l2[i - 1] + 2 * l[i - 1] + 1) * x;
f[i] = f[i - 1] + (3 * l2[i - 1] + 3 * l[i - 1] + 1) * x;
}
printf("%.1lf\n", f[n]);
return 0;
}
时间: 2024-11-01 05:25:11