Codeforces Round #293 (Div. 2) D. Ilya and Escalator
Posted mrzdtz220
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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} imes p)
(f_{i + 1, j} = f_{i, j} imes (1 - p))
(f_{i+1,n}=f_{i,n})
答案即为 (sum f_{t, i} imes 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
", ans);
return 0;
}
以上是关于Codeforces Round #293 (Div. 2) D. Ilya and Escalator的主要内容,如果未能解决你的问题,请参考以下文章
[ACM]Codeforces Round #534 (Div. 2)
Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)
Codeforces Educational Codeforces Round 67
Codeforces Round 1132Educational Round 61
codeforces Technocup 2017 - Elimination Round 2/Codeforces Round #380 (Div. 2, Rated, Based on Techn