Codeforces Round #293 (Div. 2) D. Ilya and Escalator

先求出概率
设 \(f_{i,j}\) 表示第 \(i\) 秒电梯上有 \(j\) 个人的概率
则 \(f_{0,0}=1\)
\(f_{i + 1, j + 1} = f_{i, j} \times p\)
\(f_{i + 1, j} = f_{i, j} \times (1 - p)\)
\(f_{i+1,n}=f_{i,n}\)
答案即为 \(\sum f_{t, i} \times i\)

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define lp p << 1
#define rp p << 1 | 1
#define mid ((l + r) >> 1)
#define ll long long
#define db double
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define Edg int cnt=1,head[N],to[N*2],ne[N*2];void addd(int u,int v){to[++cnt]=v;ne[cnt]=head[u];head[u]=cnt;}void add(int u,int v){addd(u,v);addd(v,u);}
#define Edgc int cnt=1,head[N],to[N*2],ne[N*2],c[N*2];void addd(int u,int v,int w){to[++cnt]=v;ne[cnt]=head[u];c[cnt]=w;head[u]=cnt;}void add(int u,int v,int w){addd(u,v,w);addd(v,u,w);}
#define es(u,i,v) for(int i=head[u],v=to[i];i;i=ne[i],v=to[i])

const int N = 2e3 + 7;
db f[N][N];

int main() {
    int n, t;
    db p;
    scanf("%d%lf%d", &n, &p, &t);
    f[0][0] = 1;
    rep(i, 0, t) {
        f[i + 1][n] = f[i][n];
        rep(j, 0, n) if (f[i][j]) {
            f[i + 1][j] += f[i][j] * (1.0 - p);
            f[i + 1][j + 1] += f[i][j] * p;
        }
    }
    db ans = 0;
    rep(i, 0, n + 1) ans += f[t][i] * i;
    printf("%.7f\n", ans);
    return 0;
}

原文地址:https://www.cnblogs.com/Mrzdtz220/p/12334112.html

时间: 2024-10-10 01:20:24

Codeforces Round #293 (Div. 2) D. Ilya and Escalator的相关文章

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

dp[i][j]表示第i秒电梯进去的人数为j时的概率.由于概率比较好求,而且这里的样本是有限个.所以可以先求出概率,然后用公式转化成期望. #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <

递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries

题目传送门 1 /* 2 递推:用cnt记录前缀值,查询区间时,两个区间相减 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cmath> 7 #include <cstring> 8 using namespace std; 9 10 const int MAXN = 1e5 + 10; 11 const int INF = 0x3f3f3f3f; 12 char s[MAXN]; 1

贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

题目传送门 1 /* 2 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 3 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 12 13 co

Codeforces Round #293 (Div. 2)

 A Vitaly and Strings 题意:给定长度相等的字符串s,t,且s的字典序小于t,求一个字符串q字典序大于s小于t. 分析:将字符串看做26进制的数,对s”+1“即可. #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define esp 1e-14 #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #defi

Codeforces Round #186 (Div. 2)---D. Ilya and Roads

Everything is great about Ilya's city, except the roads. The thing is, the only ZooVille road is represented as n holes in a row. We will consider the holes numbered from 1 to n, from left to right. Ilya is really keep on helping his city. So, he wan

Codeforces Round #311 (Div. 2)A Ilya and Diplomas

[比赛链接]click here~~ [题目大意] n个人,获取一到三等文凭,每门文凭有大小范围,求最后文凭各颁发多少 [解题思路]直接枚举了, 看完题,赶紧写了一发代码,发现居然错过注册时间,系统提示不能提交代码,真是醉了~~,以后还是得提前注册: A题,比较简单: 代码: #include <iostream> #include <bits/stdc++.h> using namespace std; int main() { int n,m; int a1,a2; int b

Codeforces Round #297 (Div. 2)C. Ilya and Sticks

题意:给你n 个木头的长度   ,  问你组成矩形的最大总面积为多少,  且木头长度L   可以当作L-1 来使用. 题解:很显然   组成矩形要保证总面积最大   只有大的和大的边组成才能保证面积最大,并且如果当前大的为偶数条那么不需要变成-1  否则变成减1   从头到尾扫一遍  没了 代码: #include<stdio.h> #include<iostream> #include<algorithm> using namespace std; __int64 v

Codeforces Round #293 (Div. 2)(A, B, C, D)

A: 模拟26进制加法即可 /************************************************************************* > File Name: cf-293-a.cpp > Author: ALex > Mail: [email protected] > Created Time: 2015年02月25日 星期三 13时40分05秒 *********************************************

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/