Uva-11021-tribles (probability expectation)

Source: Internet
Author: User

Link uva-11021

Test instructions: Start with K only hemp ball, each live one day die, every death will have pi probability of birth I only hemp ball. The probability of the death of the MA after M days.

Idea: The death of each hemp ball is independent, ask for a hemp ball, M days die the probability is f[m]
by full probability formula f[i] = P0 + p1 * F (i-1) + P2 * F (i-1) ^2 + p3 * F (i-1) ^3....pn-1 * F (i-1) ^n-1
Because it is to use f[i-1] to express a hemp ball i-1 the probability of death all, J offspring all death is F[i-1]^j, is the J-time side. Pj*f[i-1]^j said the fur ball, the birth of a J offspring, they all died in i-1 days.
So K-balls, M-days, the probability of death is f[m]^k.

Code:

#include <iostream> #include <cstdio> #include <cmath> #include <cstring>using namespace std; const int N = 1005;double P[n],f[n];int main () {    int t;    CIN >> T;    int n,k,m;    for (int ca = 1;ca <= t;ca++)    {        cin >> n >> k >> m;        for (int i = 0;i < n;i++)            scanf ("%lf", &p[i]);        memset (F,0,sizeof (f));        F[1] = p[0];        Recursive for        (int i = 2;i <= m;i++)        {for            (int j = 0;j < n;j++)                F[i] + = P[j]*pow (f[i-1],j);        }        printf ("Case #%d:%.7lf\n", Ca,pow (F[m],k));    }    return 0;}


Uva-11021-tribles (probability expectation)

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.