Description
Input
Output
Sample Input
input | output |
---|---|
5 | 26.66666666666 |
Notes
First, the rockets with numbers 1 and 5 are launched. 10 seconds later the rocket 3 is launched with probability 1/3; in that case, 10 more seconds later the rockets 2 and 4 are launched, and the firework is over after 20 seconds. In case the rocket 2 or rocket 4 is launched in the second salvo (this happens with probability 2/3), the firework is over after 30 seconds.
题目的意思给你n个火箭排成一排
一开始点燃第一个和最后一个火箭
然后每次只能在点燃过的火箭中的火箭
每两次点燃火箭的间隔时间为10s求
点燃n个火箭等待时间的期望
设dp【i,j】表示i个火箭等待了j次
那么求花费j次的概率为 dp[【i,j】=dp【i,j-1】
然后就枚举长度和次数
ACcode:
#include <cstdio>
#include <cstring>
#include <iostream>
#define maxn 404
using namespace std;
double dp[maxn][maxn];
int main(){
int n;
while(~scanf("%d",&n)){
n-=2;
for(int i=0;i<=n;++i)for(int j=i;j<=n;++j)dp[i][j]=1.0;
for(int i=1;i<=n;i++){
double e=1.0/i;
for(int j=2;j<i; j++){
dp[i][j]=dp[i][j-1];
for(int k=1;k<=i;k++){
int l=k-1,r=i-k;
double p1=dp[l][j-1],p2=dp[r][j-1],p3=dp[l][j-2],p4=dp[r][j-2];
dp[i][j]+=e*(p1*p2-p3*p4);
}
}
}
double ans = 0;
for(int i = 1; i <= n; i++){
ans += (dp[n][i]-dp[n][i-1])*i*10;
}
printf("%.11lf\n",ans);
}
return 0;
}