11021 - Tribles
GRAVITATION, n.
“The tendency of all bodies to approach one another with a strengthproportion to the quantity of matter they contain – the quantity ofmatter they contain being ascertained by the strength of their tendencyto approach one another. This is a lovely and edifying illustration ofhow science, having made A the proof of B, makes B the proof of A.”Ambrose BierceYou have a population of k Tribbles. This particular species of Tribbles live for exactly one day andthen die. Just before death, a single Tribble has the probability Pi of giving birth to i more Tribbles.What is the probability that after m generations, every Tribble will be dead?InputThe first line of input gives the number of cases, N. N test cases follow. Each one starts with a linecontaining n (1 ≤ n ≤ 1000), k (0 ≤ k ≤ 1000) and m (0 ≤ m ≤ 1000). The next n lines will give theprobabilities P0, P1, . . . , Pn−1.OutputFor each test case, output one line containing ‘Case #x:’ followed by the answer, correct up to anabsolute or relative error of 10−6.Sample Input43 1 10.330.340.333 1 20.330.340.333 1 20.50.00.54 2 20.50.00.00.5Sample OutputCase #1: 0.3300000Case #2: 0.4781370
Case #3: 0.6250000Case #4: 0.3164062题解:求概率,由全概率公式可以得到f[i]=p[0]+p[1]f[i-1]+p[2]f[i-1]^2+......+p[n-1]f[i-1]^[n-1];
题意就是给你一系列概率代表生i个麻球的概率,让求m天后都死亡的概率;This particular species of Tribbles live for exactly one day and
then die.说明包括中途死的;p[j]*f[i-1]^j代表这个麻球生了j个后代,他们在I-1天全死亡的概率;由于是独立的所以是j次方;最后结果还要k次方;
代码:
#include#include #include #include #include using namespace std;#define mem(x,y) memset(x,y,sizeof(x))const int MAXN=1010;double p[MAXN],f[MAXN];int main(){ int T,n,k,m,kase=0; scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&k,&m); for(int i=0;i