UVA

题目链接:

http://vjudge.net/problem/UVA-11021

Tribles

Time Limit: 3000MS

题意

有k只麻球,每只活一天就会死亡,临死之前可能会出生一些新的麻球。生i个麻球的概率为pi,求m天后所有麻球死亡的概率。不足m天死光也算。

题解

每只麻球后代独立生存的,所以是独立概率。
设dp[i]表示一只麻球,i天后全部死亡的概率。有递推式:
dp[i]=p0+p1dp[i-1]+p2dp[i-1]2+...+pn-1*dp[i-1](n-1))
最后答案为dp[m]^k。

代码

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf

typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;

const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);

//start----------------------------------------------------------------------

const int maxn=1010;

double pro[maxn];
double dp[maxn];
int n,k,m;

int main() {
    int tc,kase=0;
    scf("%d",&tc);
    while(tc--){
        scf("%d%d%d",&n,&k,&m);
        rep(i,0,n) scf("%lf",&pro[i]);

        dp[1]=pro[0];
        for(int i=2;i<=m;i++){
            dp[i]=0;
            for(int j=0;j<n;j++){
                dp[i]+=pro[j]*pow(dp[i-1],j);
            }
        }

        prf("Case #%d: %.7lf
",++kase,pow(dp[m],k));
    }
    return 0;
}

//end-----------------------------------------------------------------------
原文地址:https://www.cnblogs.com/fenice/p/5966340.html