# UVA 11181 probability| Given

Source: Internet
Author: User

Conditional probability, R personal buy things under the conditions of the I person to buy the probability P (ai| B). and P (ai| b) =p (AiB)/p (b), where P (AiB) represents the probability that the event AI and event b occur simultaneously, p (b) is the probability that the B event occurred

The first example

3 2

0.10

0.20

0.30

P (B) The probability of buying something for two people, p (AiB) is the probability that I would buy something for the first time. Two people buy things, can be bought, p for 0.1*0.2* (1-0.3) =0.014;1,3 buy for 0.024;2,3 buy for 0.054,

Then P (b) =0.014+0.024+0.054,p (A1B) =0.014+0.024,p (A2B) =0.014+0.054,p (a3b) =0.024+0.054, then each divided by P (b)

`1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intn,r,cas=1, buy[ -];8 Doublep[ -],sum[ -],tot;9 Ten voidCMN (intXintnum) One { A     if(num>=R) -     { -         DoublePi=1; the          for(intI=0; i<n;i++) -             if(Buy[i]) pi*=P[i]; -             Elsepi*=1-P[i]; -tot+=Pi; +          for(intI=0; i<n;i++) -             if(Buy[i]) sum[i]+=Pi; +         return; A     } at     if(x>=n)return; -      for(inti=x;i<=n-r+num;i++) -     { -buy[i]=1; -CMN (i+1, num+1); -buy[i]=0; in     } - } to  + /* - void Cmn (int x,int num) the { * if (num>=r) \$     {Panax Notoginseng double pi=1; - for (int i=0;i<n;i++) the if (Buy[i]) pi*=p[i]; + else pi*=1-p[i]; A Tot+=pi; the for (int i=0;i<n;i++) + if (buy[i]) Sum[i]+=pi; - return; \$     } \$ if (x>n-r+num) return; - buy[x]=1; - Cmn (x+1,num+1); the buy[x]=0; - Cmn (x+1,num);Wuyi } the */ - intMain () Wu { -      while(SCANF ("%d%d", &n,&r) = =2&& (n| |R)) About     { \$printf"Case %d:\n", cas++); -          for(intI=0; i<n;i++) -scanf"%LF",&p[i]); -memset (SUM,0,sizeof(sum)); Amemset (Buy,0,sizeof(Buy)); +tot=0; theCMN (0,0); -          for(intI=0; i<n;i++) \$printf"%.6lf\n", sum[i]/tot); the     } the     return 0; the}`
View Code

UVA 11181 probability| Given

Related Keywords:

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.