链接
https://odzkskevi.qnssl.com/444d7168afcef2b7afa5f44a5b07a2bc?v=1537573313
题解
每只麻球的后代都是独立繁衍的,所以可以分开来算,用
f
(
i
)
f(i)
f(i)表示开始只有一只麻球,在第
i
i
i天还剩
0
0
0只麻球的概率,
f
(
1
)
=
p
0
f(1)=p_0
f(1)=p0,
f
(
2
)
=
p
0
+
p
1
(
f
1
)
+
p
2
f
2
(
1
)
+
p
3
f
3
(
1
)
+
.
.
.
+
p
n
−
1
f
n
−
1
(
1
)
f(2)=p_0+p_1(f1)+p_2f^2(1)+p_3f^3(1)+...+p_{n-1}f^{n-1}(1)
f(2)=p0+p1(f1)+p2f2(1)+p3f3(1)+...+pn−1fn−1(1)
类比可以得到
f
(
i
)
=
∑
j
=
0
n
−
1
p
j
f
j
(
i
−
1
)
f(i)=\sum_{j=0}^{n-1}p_jf^{j}(i-1)
f(i)=∑j=0n−1pjfj(i−1)
答案是
f
k
(
m
)
f^k(m)
fk(m)
代码
//概率dp
#include <bits/stdc++.h>
#define maxn 1010
#define eps 1e-8
#define cl(x) memset(x,0,sizeof(x))
using namespace std;
double f[maxn], p[maxn];
int n, k, m;
int read(int x=0)
{
int c, f=1;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-48;
return f*x;
}
int main()
{
int i, j, T=read(), kase;
for(kase=1;kase<=T;kase++)
{
printf("Case #%d: ",kase);
cl(f);
n=read(), k=read(), m=read();
for(i=0;i<n;i++)scanf("%lf",p+i);
f[1]=p[0];
for(i=2;i<=m;i++)for(j=0;j<n;j++)f[i]+=pow(f[i-1],j)*p[j];
printf("%.10lf\n",pow(f[m],k));
}
return 0;
}