"Uva11181" probability | given (Probability

Source: Internet
Author: User

Title turn: PAC text alt meaning org lock

Question Translation

N people are going to buy things. The probability of buying things is P [I].

Now I know that R people have bought things. In this case, I want to calculate the probability that everyone will buy things.

Thanks @ s_r_f for providing translation

Description

PDF

Input/Output Format

Input Format:

 

 

Output Format:

 

 

Input and Output sample input sample #1: Copy
3 20.100.200.305 10.100.100.100.100.100 0
Output example #1: Copy
Case 1:0.4130430.7391300.847826Case 2:0.2000000.2000000.2000000.2000000.200000
Question

What is this question about ?!!! (Crying

Set $ e $ to event "$ r$ items bought by individuals", $ e_ I $ to event "No. $ I $ items bought by individuals ".

According to the formula, $ P (e_ I | E) = P ({e_ I} e)/P (e) $.

The problem is converted to $ P (e) $ and $ P ({e_ I} e) $.

For $ P (e) $, use $ DFS $ to list whether or not each user has bought it.

Set $ DFS $ to the first $ I $ individual, the person before itCombination of purchased or notThe probability is $ now $,

If you buy $ I $, the probability is $ now * P [I] $; otherwise, $ now * (1-p [I]) $.

Let's just move it over again.

When $ DFS $ arrives at $ N $, and $ r$ is bought,

Then $ P (e) + = now $.

Then, find $ P ({e_ I} e) $.

In fact, it is almost the same, but there is an additional limit of "the $ I $ individual must buy", so force the $ I $ individual to buy at $ DFS $.

1 qwerta 2 uva11181 probability | given accepted 3 code C ++, 0.79kb 4 submission time 18:50:22 5 elapsed time/memory 200 ms, 0kb 6 7 # include <iostream> 8 # include <cstdio> 9 Using namespace STD; 10 double p [23]; 11 double PE; 12 int n, R; 13 void DFS (int x, int D, double now) 14 {15 if (D> r) return; 16 if (x = n + 1) 17 {18 if (D = R) 19 PE + = now; 20 return; 21} 22 // mark23 DFS (x + 1, D + 1, now * P [x]); 24 // dismark25 DFS (x + 1, D, now * (1-p [x]); 26 return; 27} 28 double PEI; 29 void DFSs (int x, int D, int I, double now) 30 {31 if (D> r) return; 32 If (x = n + 1) 33 {34 if (D = r) 35 Pei + = now; 36 return; 37} 38 If (x = I) 39 {DFSs (x + 1, d + 1, I, now * P [x]); return;} 40 // mark41 DFSs (x + 1, D + 1, I, now * P [x]); 42 // dismark43 DFSs (x + 1, D, I, now * (1-p [x]); 44 return; 45} 46 int main () 47 {48 IOs: sync_with_stdio (false); 49 int Tim = 0; 50 while (CIN> N> r) 51 {52 If (n = 0) break; 53 printf ("case % d: \ n", ++ Tim); 54 for (INT I = 1; I <= N; ++ I) 55 CIN> P [I]; 56 Pe = 0; 57 DFS (1, 0); 58 for (INT I = 1; I <= N; ++ I) 59 {60 Pei = 0; 61 DFSs (1, 0, I, 1); 62 printf ("%. 6f \ n ", PEI/PE); 63} 64} 65 return 0; 66}

 

"Uva11181" probability | given (Probability

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.