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. 带KEY的SCP命令,老是要查,这次写在这里吧,

    有些东东记不住,急要用时老是想不起,放在这里吧, scp -r -i /xxx/rsa.key -P port user@ip:/source/ /target/

  2. FJ省队集训DAY4 T2

    XXX #include<cstdio> #include<iostream> #include<cmath> #include<cstring> #i ...

  3. 如何在Protel99se中批量修改元件的封装

    有时候需要批量修改元件的封装,可在原理图和PCB中批量修改.本文以批量修改电阻AXIAL0.3 的封装为AXIAL0.4 为例. 1. 在原理图中批量修改1.1. 方法1双击需要修改封装的其中一个元件 ...

  4. 使用脚本管理IIS

    参考资料https://technet.microsoft.com/zh-cn/library/cc779108(WS.10).aspxhttps://technet.microsoft.com/zh ...

  5. 函数call相关[ASM]

    前言:   __cdecl:C/C++函数默认调用约定,参数依次从右向左传递,并压入堆栈,最后由调用函数清空堆栈,这种方式适用于传递参数个数可变的被调用函数,只有被调用函数才知道它传递了多少个参数给被 ...

  6. Android Toast简介

    Toast是Android中一种提供给用户简短信息的视图,该视图已浮于应用程序之上的形式呈现给用户.因为它并不获得焦点,即使用户正在输入什么也不会受到影响.它的目标是尽可能以不显眼的方式,使用户看到你 ...

  7. Manacher算法----最长回文子串

    题目描述 给定一个字符串,求它的最长回文子串的长度. 分析与解法 最容易想到的办法是枚举所有的子串,分别判断其是否为回文.这个思路初看起来是正确的,但却做了很多无用功,如果一个长的子串包含另一个短一些 ...

  8. iPhone、iPod和iPad离线固件升级的方法

    我们知道iOS升级的过程过程超级简单,特别是在线升级只需要点击几个按钮就ok了,但是对于开发者来说,经常升级的iOS固件都是preview版的,需要自己下载好固件之后,手动来更新,我找了一下网上的资料 ...

  9. 初学者学Java设计模式(一)------单例设计模式

    单例设计模式 单例设计模式是指一个类只会生成一个对象,优点是他可以确保所有对象都访问唯一实例. 具体实现代码如下: public class A { public static void main(S ...

  10. 数学之路(3)-机器学习(3)-机器学习算法-PCA

    PCA 主成分分析(Principal components analysis,PCA),维基百科给出一个较容易理解的定义:“PCA是一个正交化线性变换,把数据变换到一个新的坐标系统中,使得这一数据的 ...