codeforces 518D
有n个人,每秒有p的概率有一个人进电梯,问t秒后电梯里的人数的期望。
#include
#include
#include
#include
#define MAX 2007
using namespace std;
double dp[MAX][MAX],p;
int n,t;
int main ( )
{
while ( ~scanf ( "%d%lf%d" , &n , &p , &t ) )
{
memset ( dp , 0 , sizeof ( dp ));
dp[0][0] = 1;
for ( int i = 1 ; i <= t ; i++ )
for ( int j = 0 ; j <= n ; j++ )
{
if ( j == n )dp[i][j] = dp[i-1][j];
else dp[i][j] = (1-p)*dp[i-1][j];
if ( j )
dp[i][j] += p*dp[i-1][j-1];
//sum[i][j] += sum[i-1][j] + dp[i][j];
}
double ans = 0;
for ( int i = 1 ; i <= n ; i++ )
ans += dp[t][i]*i;
printf ( "%.7f\n" , ans );
}
}