Codeforces Round #293 (Div. 2) D. Ilya and Escalator (概率DP)
2015-02-25 22:27
507 查看
dp[i][j]表示第i秒电梯进去的人数为j时的概率。由于概率比较好求,而且这里的样本是有限个。所以可以先求出概率,然后用公式转化成期望。
#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL __int64
#define pi acos(-1.0)
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double eqs=1e-9;
double dp[2015][2015];
int main()
{
int n, t, i, j, k;
double p, ans;
while(scanf("%d%lf%d",&n,&p,&t)!=EOF){
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(i=1;i<=t;i++){
for(j=0;j<=n;j++){
dp[i][j]=dp[i-1][j-1]*p;
if(j!=n) dp[i][j]+=dp[i-1][j]*(1-p);
else dp[i][j]+=dp[i-1][j];
}
}
ans=0;
for(i=1;i<=min(n,t);i++){
ans+=i*dp[t][i];
}
printf("%.7f\n",ans);
}
return 0;
}
#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL __int64
#define pi acos(-1.0)
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double eqs=1e-9;
double dp[2015][2015];
int main()
{
int n, t, i, j, k;
double p, ans;
while(scanf("%d%lf%d",&n,&p,&t)!=EOF){
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(i=1;i<=t;i++){
for(j=0;j<=n;j++){
dp[i][j]=dp[i-1][j-1]*p;
if(j!=n) dp[i][j]+=dp[i-1][j]*(1-p);
else dp[i][j]+=dp[i-1][j];
}
}
ans=0;
for(i=1;i<=min(n,t);i++){
ans+=i*dp[t][i];
}
printf("%.7f\n",ans);
}
return 0;
}
相关文章推荐
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP
- Codeforces Round #293 (Div. 2) -- D. Ilya and Escalator(概率DP)
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator(概率DP)
- Codeforces Round #293 (Div. 2)D. Ilya and Escalator(概率DP)
- CF518D. Ilya and Escalator [概率DP]
- codeforces 518D D. Ilya and Escalator(概率dp)
- codeforces--518D--Ilya and Escalator--概率DP
- Ilya and Escalator - CodeForces 518 D 概率dp
- codeforces 518D. Ilya and Escalator 概率dp
- CodeForces 518 D.Ilya and Escalator(概率DP)
- Codeforces 518D Ilya and Escalator【概率dp】
- 【DP】 Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- CF 518 D. Ilya and Escalator 概率dp
- 概率dp- Ilya and Escalator
- CodeForces 518 D. Ilya and Escalator(概率DP)
- dp(Codeforces Round #293 (Div. 2)D. Ilya and Escalator)
- Codeforces 518D Ilya and Escalator (概率dp)
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator
- 【Codeforces Round 333 (Div 2)E】【期望DP概率做法 树状数组转前缀和】Kleofáš and the n-thlon n场比赛m个人获得总名次的期望