Uva 11021-tribles (probability + recursion)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.