zoukankan      html  css  js  c++  java
  • UVa11021 Tribles

    概率 递推

    每只麻球都是独立计算的。

    可以递推,设f[i]表示一只麻球经过i天死光的概率,那么f[i]的k次方就是k只麻球经过i天死光的概率。

    f[i]=p[0]+p[1]*f[i-1]^1+p[2]*f[i-1]^2+...+p[n-1]*f[i-1]^(n-1)

    ↑直接死掉;生了一只,这一只在i-1天后死了;生了两只,这两只在i-1天后都死了...以此类推

     1 /*by SilverN*/
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdio>
     6 #include<cmath>
     7 using namespace std;
     8 int n,k,m;
     9 double p[1010],f[1010];
    10 int main(){
    11     int T;
    12     int i,j;
    13     scanf("%d",&T);
    14     int cas=0;
    15     while(T--){
    16         scanf("%d%d%d",&n,&k,&m);
    17         for(i=0;i<n;i++)scanf("%lf",&p[i]);
    18         memset(f,0,sizeof f);
    19         f[0]=0;f[1]=p[0];
    20         for(i=2;i<=m;i++){
    21             for(j=0;j<n;j++){
    22                 f[i]+=p[j]*pow(f[i-1],j);
    23             }
    24         }
    25         printf("Case #%d: %.7f
    ",++cas,pow(f[m],k));
    26     }
    27     return 0;
    28 }
  • 相关阅读:
    Out of Hay POJ
    Sum Problem hdu 1001
    N! hdu 1042
    线性表的链式表示和实现(插入删除建空合并)
    NYOJ 1007
    NYOJ 954
    NYOJ 998
    NYOJ 455
    NYOJ 975
    数据结构复习0---线性表
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/6294104.html
Copyright © 2011-2022 走看看