uva11181 - Probability|Given 条件概率

原创 2013年12月03日 10:03:37

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 is finished you are given the information that exactly r of them has bought something and others have bought nothing. Given this information you will have to find their individual buying probability.

 

Input

The input file contains at most 50 sets of inputs. The description of each set is given below:

 

First line of each set contains two integers N (1 ≤ N ≤ 20) and r(0 ≤ r ≤ N). Meaning of N and r are 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 have at most two digits after the decimal point. 

 

Input is terminated by a case where the value of N and r is zero. This case should not be 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 have six digits after the decimal point. Follow the exact format shown in output for sample input. Small precision errors will be allowed. For reasonable precision level use double precision floating-point numbers.

 

Sample Input                             Output for Sample Input

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

Case 1:

0.413043

0.739130

0.847826

Case 2:

0.200000

0.200000

0.200000

0.200000

0.200000


  给你每个人做一件事的概率,告诉你有几个人做了这件事,求每个人在这个条件下做这件事的概率。

  哎~~概率论~P(A|B) = P(AB)/P(B)

  B就是N个人里面有r人做这件事。P(B)怎么算?因为N不大,用DFS来。DFS(int cur,int r,double pi),cur是当前该判断第cur个人的状态,r是当前已经选了r个人,pi是当前已经确定的选择的概率。注意不能到r==R就返回,因为前面选到了R后面就不能再选,要到cur>N时判断r是否等于R。

#include<cstring>
#include<cstdio>
#include<iostream>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
int N,R,cas=0;
double a[25],p[25];
double DFS(int cur,int r,double pi){
    if(cur>N) return r==R?pi:0;
    double s;
    s=DFS(cur+1,r+1,pi*p[cur]);
    a[cur]+=s;
    s+=DFS(cur+1,r,pi*(1-p[cur]));
    return s;
}
int main(){
    freopen("in.txt","r",stdin);
    while(scanf("%d%d",&N,&R),N||R){
        int i;
        for(i=1;i<=N;i++) scanf("%lf",&p[i]);
        memset(a,0,sizeof(a));
        double s=DFS(1,0,1);
        printf("Case %d:\n",++cas);
        for(i=1;i<=N;i++) printf("%.6lf\n",a[i]/s);
    }
    return 0;
}




统计学 入门基础概念篇 Probability 概率部分 (个人笔记)

排列 \ 组合  Combination : sometimes, we want to count all of the possible ways that a single set of ob...
  • YtdxYHZ
  • YtdxYHZ
  • 2016年06月09日 02:43
  • 4713

概率质量函数(Probability Mass Function)和期望课程笔记

随机变量的数学定义从样本空间到实数值的映射函数。一个样本空间可以定义多个随机变量一个或几个随机变量的函数构成一个新的随机变量概率质量函数的定义pX(x)=P(X=x)=P({ω∈Ω s.t.X(ω)=...
  • xlinsist
  • xlinsist
  • 2016年03月04日 14:52
  • 8434

uva 11181(条件概率)

Problem G Probability|Given Input: Standard Input Output: Standard Output N friends go to the l...
  • Wiking__acm
  • Wiking__acm
  • 2013年03月05日 09:46
  • 1812

Uva 11181 Probability|Given(概率dp)

Problem G Probability|Given Input: Standard Input Output: Standard Output   N friends go to the...
  • u014737310
  • u014737310
  • 2015年04月27日 23:16
  • 543

uva11181 条件概率

N friends go to the local super market together. The probability of their buying something from the ...
  • winter2121
  • winter2121
  • 2017年10月31日 11:18
  • 268

UVa11181 条件概率(紫书327页)

时间限制:1秒 内存限制:64M 【问题描述】   有n个人准备去超市逛,其中第i个人买东西的概率是Pi,逛完以后你得知有r个人买了东西。根据这一信息,请计算每个人实际买了东西的概率。输入 n ...
  • qq_35546274
  • qq_35546274
  • 2017年03月16日 15:49
  • 172

UVa 11181 Probability|Given

Problem G Probability|Given Input: Standard Input Output: Standard Output   N friends go to the...
  • u011385365
  • u011385365
  • 2013年11月29日 09:32
  • 783

UVA 11181 Probability|Given dfs模拟组合情况(周赛F题)

条件模拟,这题纠结了好久,题目本身就看了好久才理解题意…… 题目大意:有n个人去超市买东西,给出r,每个人买东西的概率是p[i],求:当有r个人买东西的时候,第i个人恰好买东西的概率。 例如: 3 ...
  • u011466175
  • u011466175
  • 2013年11月09日 10:35
  • 642

UVa 11181 Probability|Given (DFS&贝叶斯公式)

11181 - Probability|Given Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=c...
  • synapse7
  • synapse7
  • 2013年12月01日 16:33
  • 1077

Uva--11181--Probability|Given

一道概率题,高中的知识,算了半天没搞明白第一个样例结果怎么得到的,然后还是百度了。。。 公式是这个: 叫做贝叶斯公式(高中时没听过这个叫法) 看到这公式我还是没看明白,直到看到这...
  • zzzz40
  • zzzz40
  • 2013年12月04日 23:56
  • 579
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:uva11181 - Probability|Given 条件概率
举报原因:
原因补充:

(最多只允许输入30个字)