Topic Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=1962
The main topic: give you k a hair ball, each hair ball can only survive one day, but each hair ball has pi probability multiply I a hair ball, ask the probability of death of all hair balls in M days. (All wool balls are independent and non-existent)
Problem-solving ideas: first, because each hair ball does not affect each other, so K-only hair ball m days of death probability is a hair ball m days after the probability of death of K-th square. The next analysis of a hair ball: if a hair ball in the first day after the death of all the probability of f[i], then it is known that the total death of the hair ball after the probability that the hair ball breeding 0 of the probability of a ball, that is, f[0].
The full probability formula is known: F[i]=p0+p1*f[i-1]+p2*f[i-1]^2+p3*f[i-1]^3+...+p (n-1) *f[i-1]^ (n-1).
Among them, Pj*f[i-1]^j said the fur ball gave birth to J Offspring, they all died in i-1 days. Therefore, the probability of death of K-Balls M is f[m]^k;
The code is as follows:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main ()
{
int t,n,k,m,cas=1;
Double p[1010],f[1010];
scanf ("%d", &t);
while (t--)
{
scanf ("%d%d%d", &n,&k,&m);
for (int i=0;i<n;i++)
scanf ("%lf", &p[i]);
F[0]=0.0;F[1]=P[0];
for (int i=2;i<=m;i++)
{
f[i]=0;
for (int j=0;j<n;j++)
{
f[i]+=p[j]*pow (f[i-1],j);
}
}
Double Ans=pow (f[m],k);
printf ("Case #%d:%.7lf\n", Cas++,ans);
}
return 0;
}