uva 11021-Tribbles-全概率

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 k Tribbles. 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 mgenerations, 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
 


k个虫子,每个虫子只能活一天。在虫子死时有pi的概率生出i个新虫子(0<=i<=n-1),求在m天后虫子全部死亡的概率。

(注意:虫子在m天之前死光也算)

题解:

独立+全概率公式.k个虫子死亡相互独立,所以考虑一个虫子:m天后全死光的概率f(m)

则有:f(i)=p(0)+p(1)*f(i-1)+p(2)*(f(i-1)^2)+...+p(n-1)*(f(n-1)^(n-1))

代码:

#include <stdio.h>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring> 
#include <cmath>
#define setbit(x,y) x|=(1<<(y)) //将X的第Y位置1
#define clrbit(x,y) x&=~(1<<(y)) //将X的第Y位清0
#define sf scanf
#define pf printf
#define INF 1 << 29
#define eps 1e-6
const double PI = acos(-1.0);               
#define lint __int64
#define LL long long 
#define MAX 1e9 + 7
#define maxn 10005
//101^110=011 异或
#define ULLint unsigned long long //2^64-1>1.8*10^19 
#define clr(x) memset(x, 0, sizeof(x))
#define Clr(x) memset(x, -1, sizeof(x))
#define TT 1006

using namespace std;

double d[TT], P[TT];
int m, n, k;

void init() {
	memset(d, 0, sizeof(d));
	memset(P, 0, sizeof(P));
}

void input() {
	scanf("%d%d%d", &n, &k, &m);
	for (int i=0; i<n; ++i){
		scanf("%lf", &P[i]);
	}
}

void solve() {
	d[1] = P[0];
	for (int i=2; i<=m; ++i){
		d[i] = 0;
		for (int j=0; j<n; ++j){
			d[i] += P[j]*pow(d[i-1], (double)j);
		}
	}
}

void output(int i) {
	double ans = 1;
	for (int i=0; i<k; ++i){
		ans *= d[m];
	}
	printf("Case #%d: %.8f\n", i, ans);
}

int main(void) {
	int t, i;
	while (~scanf("%d", &t)){
		i = 0;
		while (t --){
			init();
			input();
			solve();
			output(++i);
		}
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值