期望dp
f
[
i
]
f[i]
f[i]代表的是当q值为i时的期望
则可以发现
f
[
i
]
=
p
∗
(
1
−
i
)
∗
f
[
i
+
2
]
+
(
1
−
p
)
∗
f
[
i
+
1.5
]
+
1
f[i]=p * (1 - i)*f[i + 2] + (1 - p)*f[i + 1.5] + 1
f[i]=p∗(1−i)∗f[i+2]+(1−p)∗f[i+1.5]+1
#include <bits/stdc++.h>
using namespace std;
int T,t;
double p;
double f[1005];
int main(int argc,char *argv[])
{
cin >> T;
while(T--)
{
t++;
memset(f,0,sizeof(f));
cin >> p;
p = p / 100.0;
f[1000] = 1.0 / p;
for(int i = 999;i >= 20;i--)
{
f[i] = p * (1.0 - (double)i / 1000) * f[std::min(1000,i + 20)] + (1.0 - p) * f[std::min(1000,i + 15)] + 1.0;
}
printf("Case %d: %.10lf\n",t,f[20]);
}
return 0;
}