GRAVITATION , n. \The tendency of all bodies to approach one another
with a strength proportion to the quantity of matter they contain {
the quantity of matter they contain being ascertained by the strength
of their tendency to approach one another. This is a lovely and
edifying illustration of how science, having made A the proof of B,
makes B the proof of A.” Ambrose Bierce You have a population of k
Tribbles. This particular species of Tribbles live for exactly one day
and then die. Just before death, a single Tribble has the probability
P i of giving birth to i more Tribbles. What is the probability that
after m generations, every Tribble will be dead? Input The rst line
of input gives the number of cases, N . N test cases follow. Each one
starts with a line containing n (1 n 1000), k (0 k 1000) and m
(0 m 1000). The next n lines will give the probabilities P 0 ; P 1
; : : : ; P n
设
dpi
表示一个毛球,在i天之内全死光的概率。因为各个毛球的生死繁殖是独立的,可以写出转移方程
最后的答案是 dpmk 。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
double dp[1010],p[1010];
int n,m,k;
int main()
{
int i,j,k,T,K;
scanf("%d",&T);
for (K=1;K<=T;K++)
{
scanf("%d%d%d",&n,&k,&m);
for (i=0;i<n;i++)
scanf("%lf",&p[i]);
for (i=0;i<=m;i++) dp[i]=0;
for (i=1;i<=m;i++)
for (j=0;j<n;j++)
dp[i]+=p[j]*pow(dp[i-1],j);
printf("Case #%d: %.7f\n",K,pow(dp[m],k));
}
}