Test instructions
There are k bird, each bird can live one day, it can be born before death [0,n-1] bird, the probability of birth x bird is p[x]. Ask the probability of all the birds ' time in M days. (I counted the dead before M-day).
Input: T, N, K, M.
Exercises
Each bird's death and the probability of the young birds are independent of each other, then we only need to calculate the probability of a bird dying in M-day f[m] then POW (f[m],k), it is OK.
Set F[i] represents the probability of all death of the I-day when there is only one bird at the beginning; easy to get: f[0]=0; (0th day is Impossible) F[1]=p[0] (the first day all died, then he did not produce birds).
F[2]=p[0]+p[1]*pow (f[1],1) +p[2]*pow (f[1],2) + ....;(the probability of the first bird producing 0, producing 1 probabilities and dying in (2-1) days ... and).
#include <bits/stdc++.h>Const intMAXN =1050;DoubleF[MAXN],P[MAXN];intn,n,k,m;intMain () {intIc=0; scanf ("%d",&N); while(n--) {scanf ("%d%d%d",&n,&k,&m); for(inti =0; i<n;i++) scanf ("%LF",&P[i]); f[1]=p[0]; for(inti =2; I <= m;i++) {F[i]=0.0; for(intj =0; J < n;j++) F[i]+ = P[j]*pow (f[i-1],j); } printf ("Case #%d:%.7f\n",++Ic,pow (f[m],k)); } return 0;}
UVA 11021/probability