UVA11021 Tribles probability dp

Topic Portal

Meaning of the questions: began to have $ k $ rabbits are living each day to the death, each death will have a probability of birth $ pi $ $ i $ rabbits. Determination of probability $ m $ days of rabbit died.

Ideas: 

  Set $ ​​f [i] $ is the probability of a complete rabbit in the i-th day of death, the answer is $ f [m] ^ k $.

  So the key is seeking $ f [i] $.

     By the total probability formula was to

    $f[i]=p0+p1*f[i-1]+p2*f[i-1]^2+...+pn*f[i-1]^n$

  The formula for how to understand it? p0 is the probability of a rabbit finished the first day he died. p1 is the first born in a rabbit out of a rabbit, then the probability of this case finished at the day i die is p1 * f [i-1], due to the death of the rabbit is an independent repetition time, so the probability exponentially multiplied form.

 

  

#pragma GCC optimize (2)
#pragma G++ optimize (2)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,b,a) for(int i=b;i>=a;--i)
#define clr(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pii pair<int,int >
using namespace std;
typedef long long ll;
ll rd()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
const int maxn=1010;
const int inf=0x3f3f3f3f;
int n,m,k,T;
double dp[maxn],f[maxn],p[maxn];
int main(){
    cin>>T;
    int cat=1;
    while(T--){
        cin>>n>>k>>m;
        double res=0;
        rep(i,0,n-1){
            scanf("%lf",&p[i]);
        }
        f[1]=p[0];
        rep(i,2,m){
            f[i]=0;
            rep(j,0,n-1){
                f[i]+=p[j]*pow(f[i-1],j);
            }
        }
        printf("Case #%d: %.7f\n",cat++,pow(f[m],k));
    }
}

 

Guess you like

Origin www.cnblogs.com/mountaink/p/11448620.html