UVa 11021 - Tribles (概率DP)

39 篇文章 0 订阅
36 篇文章 0 订阅

Tribles

Time Limit: 3000MSMemory Limit: Unknown64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]  

Description

Download as PDF

Problem A
Tribbles
Input:
 Standard Input

Output: Standard Output

GRAVITATIONn.
"The tendency of all bodies to approach one another with a strength
proportion to the quantity of matter they contain -- the quantity of
matter they contain being ascertained by the strength of their tendency
to approach one another. This is a lovely and edifying illustration of
how science, having made A the proof of B, makes B the proof of A."

Ambrose Bierce

You have a population of kTribbles. This particular species of Tribbles live for exactly one day and then die. Just before death, a single Tribble has the probability Pi of giving birth to i more Tribbles. What is the probability that after m generations, every Tribble will be dead?

Input
The first line of input gives the number of cases, NN test cases follow. Each one starts with a line containing n (1<= n<=1000) , k (0<= k<=1000) and m (0<= m<=1000) . The next n lines will give the probabilities P0P1, ...,Pn-1.

Output
For each test case, output one line containing "Case #x:" followed by the answer, correct up to an absolute or relative error of 10-6.

Sample Input

Sample Output

4 
3 1 1
0.33 
0.34 
0.33 
3 1 2 
0.33 
0.34 
0.33 
3 1 2 
0.5 
0.0 
0.5 
4 2 2
0.5 
0.0 
0.0 
0.5
Case #1: 0.3300000 
Case #2: 0.4781370 
Case #3: 0.6250000 
Case #4: 0.3164062 
                      

Problemsetter: Igor Naverniouk, EPS

Special Thanks: Joachim Wulff

Source

Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Probability ::  Examples

Root :: Prominent Problemsetters ::  Igor Naverniouk (Abednego)
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Probability Theory ::  Standard

[Submit]   [Go Back]   [Status]  




题意:

有k只麻球,每只只能存活一天,临死前可能会生出一些新的麻球。具体来说,生i个麻球的概率为Pi。给定m,求m天后所有麻球都死掉的概率。


对于同一天的每只麻球是独立,可以独立来考虑

f(n)表示第一天有一只麻球,m天后全部死掉的概率

则 f(n) = sum{ P0 + P1*f(n-1) + P2*f(n-1)^2 + ... + Pi*f(n-1)^i + .. + P(n-1) * f(n-1)^(n-1) }

而答案就是 f(m) ^ K


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#define oform1 "%I64d"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#define oform1 "%lld"
#endif

#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))
#define P64I1(a) printf(oform1, (a))
#define REP(i, n) for(int (i)=0; (i)<n; (i)++)
#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)

const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const double PI = (4.0*atan(1.0));

const int maxm = 1000 + 20;
double P[maxm];
double f[maxm];

int main() {
    int T;

    scanf("%d", &T);
    for(int kase=1; kase<=T; kase++) {
        int n, K, m;
        scanf("%d%d%d", &n, &K, &m);
        for(int i=0; i<n; i++) scanf("%lf", &P[i]);
        f[0] = 0; f[1] = P[0];
        for(int i=2; i<=m; i++) {
            f[i] = P[0];
            for(int j=1; j<n; j++) {
                f[i] += P[j] * pow(f[i-1], j);
            }
        }
        double ans = pow(f[m], K);
        printf("Case #%d: %.7lf\n", kase, ans);
    }

    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值