UVA11021 tribles[discrete probability DP]

Source: Internet
Author: User

Uva-11021tribles

Gravitation, N. "The tendency of all bodies to approach one another with a strength proportion to the quantity of matter T Hey contain–the quantity of matter they contain being ascertained by the strength of their tendency to approach one anot Her. This is a lovely and edifying illustration of what science, have 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 have the probability Pi of giving birth to I more tribbles. What's the probability that after M generations, every tribble would be dead?

Input

The first line of input gives the number of cases, N. n test Cases follow. Each one starts with a line CONTAININGN (1≤n≤1000), K (0≤k≤1000) Andm (0≤m≤1000). Thenextnlineswillgivethe probabilities P0, P1, ..., pn−1.

Output

For each test case, the output one line containing ' case #x: ' followed by the answer, correct-to-an absolute or relative ER Ror of 10−6.

Sample Input

4 3 1 1 0.33 0.34 0.33 3 1 2 0.33 0.34 0.33 3 1 2 0.5 0.0 0.5 4 2 2 0.5 0.0 0.0 0.5

Sample Output

Case #1:0.3300000Case #2:0.4781370Case #3:0.6250000Case #4:0.3164062

Each ball is independent of each other, and one can be asked.
F[i] Indicates the probability of the total death of 1 balls and offspring after I days
F[i]=p[0]+p[1]*f[i-1]+p[2]*f[i-1]^2+ .....
Boundary f[0]=0
////main.cpp//uva11021////Created by Candy on 26/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;Const intn=1005;intt,n,m,k;DoubleF[n],p[n];inlineDoublefpDoubleAintb) {    Doubleans=1.0;  for(; b;b>>=1, a*=a)if(b&1) ans*=A; returnans;}voiddp () {f[0]=0;  for(intI=1; i<=m;i++) {F[i]=p[0];  for(intj=1; j<n;j++) F[I]+=P[J]*FP (f[i-1],j); }}intMainintargcConst Char*argv[]) {scanf ("%d",&T);  for(intcas=1; cas<=t;cas++) {scanf ("%d%d%d",&n,&k,&m);  for(intI=0; i<n;i++) scanf ("%LF",&P[i]);        DP (); printf ("Case #%d:%.7lf\n", CAS,FP (f[m],k)); }        return 0;}




UVA11021 tribles[discrete probability DP]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.