题解 P5249 【[LnOI2019]加特林轮盘赌】
好像正解是高消来着,但这题为什么要高消呢?
可以设
显然有转移方程:
然后考虑第
显然有
但由于这道题的精度开到了 1e-8 所以只有70分。
但是这个方程还可以继续优化成 O(n) 。
只需要考虑组合数的特殊性质即可。
但这没有什么意义,还是会被卡精度。
所以这题为什么不对概率取模然后出到 1e6 呢?
下面是没有优化复杂度的代码,只有
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define il inline
il int read()
{
int re=0,k=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')k=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){re=re*10+ch-48;ch=getchar();}
return re*k;
}
il void write(int x)
{
if(x<0){putchar('-');write(-x);return;}
if(x<10)return putchar(x+48),void();
return write(x/10),write(x%10),void();
}
#define p0 P0
double g[10005],f[10005],P0;
int n,k,jc[10005],inv;
signed main()
{
cin>>P0>>n>>k;
f[1]=1;
double T=1.0-P0;
if(P0+1e-11>1.0)
{
if(k==n)
{
puts("1.0000000000");
}
else
puts("0.0000000000");
return 0;
}
if(P0-1e-11<0.0)
{
puts("0.000000000");
return 0;
}
double P=T*T;
for(int i=2;i<=n;i++,P*=T)
{
double now=1.0/(1-P),t=P;
for(int j=1;j<i;j++)
{
t=t*P0/T;
t=t*(i-j)/(j);
f[i]+=t*now*f[i-j];
}
}
double ans=0;
P=pow(T,k-1);
for(int i=0;i<k;i++)
{
ans+=P*f[n-i];
P=P*P0/T*(k-i-1)/(i+1);
}
cout<<fixed<<setprecision(15)<<ans;
}