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 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 p i
(0.1 < p i < 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

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

题意:

有 n 个人准备去逛超市,其中第 i 人购物的概率是 Pi ,逛完以后得知有 r 人买了东西,根据这一信息,计算每人买了东西的实际概率。

x[i] 表示 第i个人是否买了东西 1买了0没买

然后用 next_permutation();

把所有的情况 表示出来

在暴力求解了。。。条件概率,贝叶斯公式

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
double r[];
double sum[];
int x[];
double tot;
int n,m;
void init(){
memset(r,,sizeof(r));
memset(sum,,sizeof(sum));
memset(x,,sizeof(x));
for(int i=;i<n-m;i++){
x[i]=;
}
tot=;
for(int i=;i<n;i++){
cin>>r[i];
}
}
int main(){
int k=;double temp=0.0;
while(cin>>n>>m&&n+m){
init();
do{
temp=;
for(int i=;i<n;i++){
if(x[i])temp*=r[i];
else temp*=-r[i];
}
tot+=temp;
for(int i=;i<n;i++){
if(x[i])sum[i]+=temp;
}
}while(next_permutation(x,x+n));
cout<<"Case "<<k++<<":"<<endl;
for(int i=;i<n;i++){
printf("%f\n",sum[i]/tot);
}
}
}

11181 - Probability|Given的更多相关文章

  1. 概率论 --- Uva 11181 Probability|Given

    Uva 11181 Probability|Given Problem's Link:   http://acm.hust.edu.cn/vjudge/problem/viewProblem.acti ...

  2. uva 11181 - Probability|Given(概率)

    题目链接:uva 11181 - Probability|Given 题目大意:有n个人去超市买东西,给出r,每个人买东西的概率是p[i],当有r个人买东西的时候,第i个人恰好买东西的概率. 解题思路 ...

  3. uva 11181 - Probability|Given

    条件概率公式:P( A|B ) = P( AB ) / P( B ) 表示在事件B发生的前提,事件A发生的可能性: 问题的: 复位事件E:r个人买东西: 事件Ei:文章i个人买东西: 的要求是P( E ...

  4. UVa 11181 - Probability|Given(条件概率)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. UVA 11181 Probability|Given (离散概率)

    题意:有n个人去商场,其中每个人都有一个打算买东西的概率P[i].问你最后r个人买了东西的情况下每个人买东西的概率 题解:一脸蒙蔽的题,之前的概率与之后的概率不一样??? 看了白书上的题解才知道了,其 ...

  6. Uva - 11181 Probability|Given (条件概率)

    设事件B为一共有r个人买了东西,设事件Ai为第i个人买了东西. 那么这个题目实际上就是求P(Ai|B),而P(Ai|B)=P(AiB)/P(B),其中P(AiB)表示事件Ai与事件B同时发生的概率,同 ...

  7. UVA - 11181 Probability|Given (条件概率)

    题意:有n个人,已知每个人买东西的概率,求在已知r个人买了东西的条件下每个人买东西的概率. 分析:二进制枚举个数为r的子集,按定义求即可. #include<cstdio> #includ ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

随机推荐

  1. Oracle 11g New 热补丁

    热补丁:概览 对于Oracle 实例上的bug 修复或诊断补丁程序,热补丁 可以执行以下操作: • 安装 • 启用 • 禁用 热补丁:概览 使用热补丁可以安装.启用和禁用 正在运行的 活动Oracle ...

  2. openrisc 之 Wishbone总线学习笔记——总线特性

    特性: 一,互联方式: 支持点到点.共享总线.十字交叉(Crossbar)和基于交换结构(Switch fabric)的互联. 二,数据操作方式:单次读/写操作.块读/写操作,读改写(RMW,Read ...

  3. Matlab近期用到的函数(持续更新)

    最近任务用到matlab较多,第一版的代码大部分对于矩阵类的计算都是用for循环来完成的,主要是思维还没有适应matlab.看了同事的一份代码后,现在遇到需要循环的地方第一反应就是如何能够用矩阵的直接 ...

  4. Log Collect

    http://ossectools.blogspot.com/2011/03/comprehensive-log-collection.html https://www.hacking-lab.com ...

  5. 基于visual Studio2013解决C语言竞赛题之0401阶乘

      题目 解决代码及点评 这个是一道经典的教科书题目,基本上每本基础的c/c++语言教科书都会有这个题目 用来演示循环语句 #include <stdio.h> #include ...

  6. 解题报告 HDU1087 Super Jumping! Jumping! Jumping!

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. ORACLE uuid自己主动生成主键

    -- Create table create table TECHNOLOGYCOMPANY ( ID VARCHAR2(32) default SYS_GUID() not null, FLOWID ...

  8. Android:源码环境下移植第三方的apk内置到ROM(System Image)中

    1. 首先在vendor目录下新建一个the3rdapk的目录,将需要内置的apk丢进去,目录名自己随意定. 2. 在 build/target/product/common.mk最后面,在$(cal ...

  9. Android 自定义view实现水波纹效果

    http://blog.csdn.net/tianjian4592/article/details/44222565 在实际的开发中,很多时候还会遇到相对比较复杂的需求,比如产品妹纸或UI妹纸在哪看了 ...

  10. PHP - __clone 对象克隆

    <?php /** * 此例子解释什么是深克隆. * 克隆学生类. */ class Student { public $name = '张三'; public $age = 12; //所属老 ...