11181-probability| Given

Source: Internet
Author: User

N friends go to the local super market together. The probability of their buying something from the
Market is P 1, p 2, p 3,..., p N respectively. After their marketing was finished you are given the information
That exactly r of them had bought something and others had bought nothing. Given This information
You'll have the to find their individual buying probability.
Input
The input file contains at most sets of inputs. The description of each set is given below:
First line of each set contains the integers N (1≤n≤20) and R (0≤r≤n). Meaning of N and
R is given in the problem statement. Each of the next N lines contains one floating-point number p I
(0.1 < P i < 1) which actually denotes the buying probability of the i-th friend. All probability values
Should has at most of the digits after the decimal point.
Input is terminated by a case where the value of N and R is zero. This case is should not being processes.
Output
For each line of input produce N +1 lines of output. First line contains the serial of output. Each of the
Next N lines contains a floating-point number which denotes the buying probability of the i-th friend
Given that exactly R has bought something. These values should has six digits after the decimal point.
Follow the exact format shown in output for sample input. Small precision errors'll be allowed. For
Reasonable precision level use double precision floating-point numbers.
Sample Input


3 2
0.10
0.20
0.30
5 1
0.10
0.10
0.10
0.10
0.10
0 0
Sample Output


Case 1:
0.413043
0.739130
0.847826
Case 2:
0.200000
0.200000
0.200000
0.200000
0.200000

Test instructions

There are n people ready to go to the supermarket, in which i the probability of shopping is Pi, after browsing to learn that R people bought something, according to this information, calculate the actual probability of each person to buy things.

X[i] Indicates whether the first person bought something 1 bought 0 did not buy

Then use Next_permutation ();

To show all the situation.

In the violence solved ... Conditional probability, Bayesian formula

#include <iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespacestd;Doubler[ +];Doublesum[ +];intx[ +];Doubletot;intn,m;voidinit () {memset (R,0,sizeof(R)); memset (SUM,0,sizeof(sum)); memset (x,1,sizeof(x));  for(intI=0; i<n-m;i++) {X[i]=0; } tot=0;  for(intI=0; i<n;i++) {cin>>R[i]; }}intMain () {intk=1;Doubletemp=0.0;  while(cin>>n>>m&&n+L)        {init ();  Do{Temp=1;  for(intI=0; i<n;i++){                if(X[i]) temp*=R[i]; Elsetemp*=1-R[i]; } tot+=temp;  for(intI=0; i<n;i++){                if(X[i]) sum[i]+=temp; }        } while(Next_permutation (x,x+N)); cout<<" Case"<<k++<<":"<<Endl;  for(intI=0; i<n;i++) {printf ("%f\n", sum[i]/tot); }    }}
View Code

11181-probability| Given

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.