The probability and expectation of UVA 11021 Tribles

Source: Internet
Author: User
Tags cas pow

Topic Link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=1962

The main topic: give you k a hair ball, each hair ball can only survive one day, but each hair ball has pi probability multiply I a hair ball, ask the probability of death of all hair balls in M days. (All wool balls are independent and non-existent)

Problem-solving ideas: first, because each hair ball does not affect each other, so K-only hair ball m days of death probability is a hair ball m days after the probability of death of K-th square. The next analysis of a hair ball: if a hair ball in the first day after the death of all the probability of f[i], then it is known that the total death of the hair ball after the probability that the hair ball breeding 0 of the probability of a ball, that is, f[0].

The full probability formula is known: F[i]=p0+p1*f[i-1]+p2*f[i-1]^2+p3*f[i-1]^3+...+p (n-1) *f[i-1]^ (n-1).

Among them, Pj*f[i-1]^j said the fur ball gave birth to J Offspring, they all died in i-1 days. Therefore, the probability of death of K-Balls M is f[m]^k;

The code is as follows:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int main ()
{
    int t,n,k,m,cas=1;
    Double p[1010],f[1010];
    scanf ("%d", &t);
    while (t--)
    {
        scanf ("%d%d%d", &n,&k,&m);
        for (int i=0;i<n;i++)
            scanf ("%lf", &p[i]);
        F[0]=0.0;F[1]=P[0];
        for (int i=2;i<=m;i++)
        {
            f[i]=0;
            for (int j=0;j<n;j++)
            {
                f[i]+=p[j]*pow (f[i-1],j);
            }
        }
        Double Ans=pow (f[m],k);
        printf ("Case #%d:%.7lf\n", Cas++,ans);
    }
    return 0;
}


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.