UVA 11021/probability

Source: Internet
Author: User

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

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.