Uva 11181 probability| Given (Probabilistic DP)

Source: Internet
Author: User

Problem G
probability| Given
Input:
standard input

Output: Standard Output

N friends go to the local super market together. The probability of their buying something from the market is respectively. After their marketing was finished you be given the information that exactly r of them have bought something and others hav E 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 (0.1<<1) which actually denotes the buying probability of the i-th friend. All probability values should has at most and 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.

Outputfor 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 a allowed. for reasonable precision level use double precision floating-point numbers.&n Bsp Sample input                              output for Sample Input
0 0

Case 1:

0.413043

0.739130

0.847826

Case 2:

0.200000

0.200000

0.200000

0.200000

0.200000

Problem-setter:shahriar Manzoor
Special Thanks:derek Kisman


Test instructions: There are n individuals, and know the probability of each person to buy things, now known to have R personal buy things, in turn, the probability of the first person to buy things

Train of thought: ans[i] The probability that the r person buys something and the first person buys something, and all represents the probability that n gives a person the first r to buy something.


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8//typedef __ Int64 ll; #define FRE (i,a,b) for (i = A; I <b; i++) #define FREE (i,b,a) for (i = b; I >= a;i--) #define MEM (T, v) MEMS ET ((t), V, sizeof (t)) #define SSF (n) scanf ("%s", N) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf (          "%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define Bug PF ("hi\n") using namespace std, #define INF 0x3f3f3f3f#define n 25double ans[n];d ouble p[n];int n,r;double dfs (int    Pos,int left,double pp) {if (pos>n) return left==0? pp:0;    Double sum=0;    if (left) {Sum+=dfs (Pos+1,left-1,pp*p[pos]);    Ans[pos]+=sum;} Sum+=dfs (pos+1,left,pp* (1-p[POS])); return sum;}    int main () {int i,j,ca=0;   while (SFF (n,r), n+r) {fre (i,1,n+1) scanf ("%lf", &p[i]); Memset (ans,0,sizeof (ans));   Double All=dfs (1,r,1);   PF ("Case%d:\n", ++CA);  for (i=1;i<=n;i++) pf ("%.6lf\n", Ans[i]/all);} return 0;}






Uva 11181 probability| Given (Probabilistic DP)

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.