BZOJ链接......它死了。

# 分析

$X_i= \begin{cases} X_{i-1}+1 & p_i\\ 0 & 1-p_i \end{cases}$

$E(X_i)=p_iE(X_{i-1}+1)+(1-p_i)E(0)=p_iE(X_{i-1})+p_i$

$X_i^2= \begin{cases} (X_{i-1}+1)^2 & p_i\\ 0^2 & 1-p_i \end{cases}$

$E(X_i^2)=p_i(E(X_{i-1}^2)+2E(X_{i-1})+1)$

$E(X_i^3)=p_i(E(X_{i-1}^3)+3E(X_{i-1}^2)+3E(X_{i-1})+1)$

$ans=\sum_{i=1}^n(1-p_{i+1})E(X_i^3)$

# 代码

#include <cstdio>

const int MAXN = 1e5 + 5;

template<typename _T>
void read( _T &x )
{
x = 0;char s = getchar();int f = 1;
while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
x *= f;
}

template<typename _T>
void write( _T x )
{
if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
if( 9 < x ){ write( x / 10 ); }
putchar( x % 10 + '0' );
}

double E1[MAXN], E2[MAXN], E3[MAXN];
double p[MAXN];
int N;

int main()
{
for( int i = 1 ; i <= N ; i ++ )
scanf( "%lf", &p[i] );
double ans = 0;
for( int i = 1 ; i <= N ; i ++ )
{
E1[i] = p[i] * ( E1[i - 1] + 1 );
E2[i] = p[i] * ( E2[i - 1] + 2 * E1[i - 1] + 1 );
E3[i] = p[i] * ( E3[i - 1] + 3 * E2[i - 1] + 3 * E1[i - 1] + 1 );
ans += E3[i] * ( 1 - p[i + 1] );
}
printf( "%.1lf\n", ans );
return 0;
}

posted @ 2020-07-29 11:26  crashed  阅读(189)  评论(0编辑  收藏  举报