UVa 11021 - Tribles (概率DP)

来源:互联网 发布:access如何输入数据 编辑:程序博客网 时间:2024/06/06 08:36

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 WINtypedef __int64 LL;#define iform "%I64d"#define oform "%I64d\n"#define oform1 "%I64d"#elsetypedef 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
原创粉丝点击