http://codeforces.com/problemset/problem/518/D

题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望

考虑dp:f[i][j]代表第i秒有j个人的概率,f[0][0]=1,f[i][j]=f[i-1][j-1]*p+f[i-1][j]*(1-p),特别有:f[i][n]=f[i-1][n]+f[i-1][n-1]*p

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
double p,f[][];
int n,t;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
double p;
n=read();scanf("%lf",&p);t=read();
f[][]=;
for (int i=;i<=t;i++){
for (int j=;j<n;j++)
f[i][j]=f[i-][j]*(-p)+f[i-][j-]*p;
f[i][n]=f[i-][n]+f[i-][n-]*p;
}
double ans=;
for (int i=;i<=n;i++)
ans+=f[t][i]*i;
printf("%.6f\n",ans);
return ;
}

Codeforces 518D Ilya and Escalator的更多相关文章

  1. ●CodeForces 518D Ilya and Escalator

    题链: http://codeforces.com/problemset/problem/518/D题解: 期望dp. 定义dp[t][i]表示在第t秒开始之前,已经有了i个人在电梯上,之后期望能有多 ...

  2. CoderForces 518D Ilya and Escalator (期望DP)

    题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...

  3. Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP

    D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. D. Ilya and Escalator

    D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. CF518D. Ilya and Escalator [概率DP]

    CF518D. Ilya and Escalator 题意:n个人,每秒p的概念队首的人进入电梯,求t秒后期望人数 直接使用期望定义 \(f[i][j]\) i秒后电梯中j个人的概率 注意n个人的时候 ...

  6. Codeforces 518 D Ilya and Escalator

    Discription Ilya got tired of sports programming, left university and got a job in the subway. He wa ...

  7. CodeForces 313C Ilya and Matrix

    Ilya and Matrix Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Su ...

  8. CF 518 D. Ilya and Escalator

    Ilya got tired of sports programming, left university and got a job in the subway. He was given the ...

  9. codeforces 842C Ilya And The Tree

    Ilya is very fond of graphs, especially trees. During his last trip to the forest Ilya found a very ...

随机推荐

  1. android中button点击频率控制

    public class Utils { private static long lastClickTime; public static boolean isFastDoubleClick() { ...

  2. 在eclipse中创建web项目

    如何创建dynamic web project项目 本文的演示是从本地文件创建dynamic web project,从svn检出的同时创建dynamic web project于此类似.我们推荐使用 ...

  3. mv command:unable to remove target: Is a director

    mv command:unable to remove target: Is a director This is somewhat simple as long as we understand t ...

  4. 【转】Math.Atan2 方法

    原文网址:https://msdn.microsoft.com/zh-cn/library/system.math.atan2.aspx 返回正切值为两个指定数字的商的角度. 命名空间:  Syste ...

  5. 怎样检查手机是否root成功

    怎样检查手机是否root成功 浏览:154361 | 更新:2011-01-20 13:10 | 标签:root 总有人以为,root后就可以删除自带程序了,这个想法也对也不对,想删除自带的软件,确实 ...

  6. C++ double类型转string类型后,怎么实现小数点后只显示一个数字

    C++ double类型转string类型后,怎么实现小数点后只显示一个数字 #include <iostream> #include <sstream> #include & ...

  7. phpcms:四、尾部包含

    四.尾部包含1.包含尾部文件:{template "content","footer"}2.栏目列表调用(关于我们| 联系方式| 版权声明| 招聘信息|):{p ...

  8. [iOS] 创建第一个应用程序项目

    开发环境:MacBook Pro XCode 5.0.1 1. 创建新的空的工程 2. 手动添加Controller 3. 将Controller添加到AppDelegate 4. 编辑.xib 5. ...

  9. Arcgis API for Android之GPS定位

    欢迎大家增加Arcgis API for Android的QQ交流群:337469080 先说说写这篇文章的原因吧,在群内讨论的过程中,有人提到了定位的问题,刚好,自己曾经在做相关工作的时候做过相关的 ...

  10. C/C++笔试准备(2)

    问题:编辑距离,是指将一个字符串变为另一个字符串,仅可以3种操作:修改一个字符,删除一个字符,插入一个字符.the变成that:删除e,插入a,插入t.20’ 实现编辑距离算法. 解算:利用动态规划的 ...