Topic Link: Click to open the link
Test instructions: K only hemp ball, every living day will die, but the next day may have some hemp ball, specifically the probability of birth I a hemp ball is pi, for m days All hemp ball death probability.
Train of thought: Consider the full probability formula, ask K only hemp ball m days after death, because death is independent event, applied multiplication, ans= f[m] ^k, f[m] for a hemp ball m days of death probability. For the first day,
F[i]=p0+p1*f[i-1]^1 +p2*f[i-1]^2 +...p (n-1) *f[i-1]^ (n-1) (is to let the i-1 day all the birth of the hemp ball all died, then the first Tianma ball is gone. )
The final answer is f[m]^k.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 1<<12#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 1000000007#define pp pair<int,int> #define ull unsigned long lon Gusing namespace Std;double f[1002],p[1002];int n,m,k;int main () {int t,cas=1;scanf ("%d", &t), while (t--) {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]=0;for (int j=0;j<n;j++) F[i]+=p[j]*pow (f[i-1],j);} printf ("Case #%d:%.7lf\n", Cas++,pow (F[m],k));} return 0;}
Uva 11021-tribles (probability + recursion)