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. 例说 AD中ROOM的使用

    从OrCAD中将网表导入之后,区别于从AD原理图中导入,笔者经过反复试验,发现在OrCAD中定义的种种区域属性,比如像Page,Class,Room,在AD中导入之后全部消失,这就意味着你本来按照模块 ...

  2. bat命令大全

    一.简单批处理内部命令简介 1.Echo 命令 打开回显或关闭请求回显功能,或显示消息.如果没有任何参数,echo 命令将显示当前回显设置.   语法 echo [{on│off}] [message ...

  3. NOI2011 NOI嘉年华

    http://www.lydsy.com/JudgeOnline/problem.php?id=2436 首先离散化,离散化后时间范围为[1,cnt]. 求出H[i][j],表示时间范围在[i,j]的 ...

  4. c语言二维数组变色龙之死字的打印

    1 #include <stdio.h> #include <stdlib.h> void main() { ][]= { {'#','#','#',' ','#','#',' ...

  5. Java:单例模式的七种写法[转]

    第一种(懒汉,线程不安全):  1 public class Singleton {   2     private static Singleton instance;   3     privat ...

  6. 曾经的足迹——对Linux CAN驱动的理解(1)

    在Ti的AM335X系列Cortext-A8芯片中,CAN模块采用D_CAN结构,实质即两路CAN接口. 在此分享一下对基于AM335X的Linux CAN驱动源码的理解.下面来分析它的驱动源码及其工 ...

  7. Python一日一练05----怒刷点击量

    功能 自己主动获取CSDN文章列表,并对每篇文章添加点击量. 源代码 import urllib.request import re import time import random from bs ...

  8. 【C疯狂的教材】(九)C语言指针(一)

    1.什么是地址? 内存是由若干个1个字节的内存单元组成的存储器 计算机为了管理内存单元.给每一个字节都进行编号 编号的就是地址 2.什么是指针? 地址就是指针 地址: 地址指向的内存单元值:编号相应的 ...

  9. 掌握jQuery插件开发,这篇文章就够了

    ---恢复内容开始--- 在实际开发工作中,总会碰到像滚动,分页,日历等展示效果的业务需求,对于接触过jQuery以及数据jQuery使用的人来说,首先想到的肯定是寻找现有的jQuery插件来满足形影 ...

  10. xhtml规范

    在使用XHTML语言进行网页制作时,必须要遵循一定的语法规范.下面进行详细讲解,其中具体内容可以分为以下几点. 文档方面: 必须定义文档类型(DTD)和你的名字空间 标签方面: 所有标签均要小写,合理 ...