UVa11021 Tribbles

你有K个麻球。一个只会存活一天。在死亡之前,一个麻球有P_i的概率生出i个麻球(i=0,1,…,n-1)。m天后所有麻球都死亡的概率是多少?(包含在第m天前全部死亡的情况)


 

麻球之间是独立的,只算一个麻球就行了

直接枚举生出几只麻球算概率

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1005;
const double eps=1e-8;
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
int n,m,k;
double p[N],f[N];
double Pow(double a,int b){
    double re=1.0;
    for(;b;b>>=1,a*=a)
        if(b&1) re*=a;
    return re;
}
int main(){
    freopen("tribbles.in","r",stdin);
    freopen("tribbles.out","w",stdout);
    int T=read(),cas=0;
    while(T--){
        n=read();k=read();m=read();
        for(int i=0;i<n;i++) scanf("%lf",&p[i]);
        f[1]=p[0];
        for(int i=2;i<=m;i++){
            f[i]=p[0];
            double po=1;
            for(int j=1;j<n;j++) po*=f[i-1],f[i]+=p[j]*po;
        }
        printf("Case #%d: %.7lf\n",++cas,Pow(f[m],k));
    }
}
View Code

相关文章:

  • 2021-07-03
  • 2022-12-23
  • 2021-12-18
  • 2021-08-12
  • 2021-07-16
  • 2022-03-08
  • 2021-10-21
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2021-11-28
  • 2021-06-07
  • 2022-01-15
  • 2022-01-24
  • 2022-12-23
相关资源
相似解决方案