zoukankan      html  css  js  c++  java
  • Uva 11021(概率)

    题意:有k只麻球,每只只能活一天,但临死之前可能产生新麻球,生出i个麻球的概率为pi,给定m,求m天后所有麻球都死亡的概率

    输入格式

      输入一行为测试数据的组数T,每组数据第一行为3个整数n,k,m;已下n行为概率,p0,p1,p2,p3,p4......;

    输出格式

     输出所求概率,保留七位有效数字。

    分析:

      每个麻球都是相互独立的,所以我们只需要考虑一个麻球的情况,

    假设在一只麻球在第i天每个死亡的概率为f(i);

    f(i)=p0+p1*f(i-1)+p2*f(i-1)^2+p3*f(i-1)^3+.....+pn-1*f(i-1)^(n-1);

    比如 f[(1)=p0;

    f(2)=p0+p1*f(1)+p2*f(1)^2+p3*f(1)^3+.....+pn-1*f(1)^(n-1);

    最终结果是pow(f(m),n);

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<map>
     8 #include<set>
     9 #include<vector>
    10 #include<cstdlib>
    11 #include<string>
    12 #define eps 0.000000001
    13 typedef long long ll;
    14 typedef unsigned long long LL;
    15 using namespace std;
    16 const int N=10000+10;
    17 int n,k,m;
    18 double p[N],f[N];
    19 int main(){
    20     int t;
    21     scanf("%d",&t);
    22     int Case=0;
    23     while(t--){
    24         scanf("%d%d%d",&n,&k,&m);
    25         for(int i=0;i<n;i++)scanf("%lf",&p[i]);
    26         f[0]=0;
    27         f[1]=p[0];
    28         for(int i=2;i<=m;i++){
    29             f[i]=0;
    30             for(int j=0;j<n;j++){
    31                 f[i]=f[i]+p[j]*pow(f[i-1],j);
    32             }
    33         }
    34         Case++;
    35         printf("Case #%d: %.7lf
    ",Case,pow(f[m],k));
    36     }
    37 }
  • 相关阅读:
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    Python for Data Science
    软件工程实践总结
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/6290032.html
Copyright © 2011-2022 走看看