# codeforces gym 103049G Great Expectations

$t(<n)$  $p(0<p<1)$  $d$($<=1000$) 三个数，表示该事件发生在正常流程下的第$t$秒时，发生概率为$p$，浪费$d$的时间。

$F[i][j]=(1-p[i])*(F[i+1][j+t[i+1]-t[i]]+t[i+1]-t[i])+p[i]*min(F[0][0],F[i+1][j+d[i]+t[i+1]-t[i]]+d[i]+t[i+1]-t[i]) (j+d[i]+n-t[i]<r)$

$F[i][j]=(1-p[i])*(F[i+1][j+t[i+1]-t[i]]+t[i+1]-t[i])+p[i]*F[0][0] (j+d[i]+n-t[i]>=r)$

 1 #include<iostream>
2 #include<cstdlib>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<algorithm>
7 #define N 5005
8 #define double long double
9 using namespace std;
10 int n,r,m;
11 int T[N];
12 double P[N];
13 int D[N];;
14 double F[55][N];
15 bool check(double X)
16 {
17     for(int i=m;i>=0;i--)
18     {
19         for(int j=T[i];j<r-(n-T[i]);j++)
20         {
21             F[i][j]=P[i]*(T[i+1]-T[i]+F[i+1][j+T[i+1]-T[i]]);
22             if(j+D[i]+(n-T[i])<r)
23             {
24                 F[i][j]+=(1.0-P[i])*min(X,D[i]+T[i+1]-T[i]+F[i+1][D[i]+T[i+1]-T[i]+j]);
25             }
26             else
27             {
28                 F[i][j]+=(1.0-P[i])*X;
29             }
30         }
31     }
32     return X>F[0][0];
33 }
34 int main()
35 {
36     scanf("%d%d%d",&n,&r,&m);
37     for(int i=1;i<=m;i++)
38     {
39         scanf("%d%Lf%d",&T[i],&P[i],&D[i]);
40     }
41     T[m+1]=n;
42     P[0]=1;
43     double li=0,ri=1e17,mid,ans;
44     while(fabs(ri-li)>=1e-8)
45     {
46         mid=(li+ri)/2.0;
47         if(check(mid)) ri=mid-(1e-8),ans=mid;
48         else li=mid+(1e-8);
49     }
50     printf("%.10Lf\n",ans);
51     return 0;
52 }
53  
View Code

posted @ 2021-05-24 21:19  Hzoi_joker  阅读(35)  评论(0编辑  收藏  举报