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. PHP 判断数据类型

    isset()://变量是否已经声明 empty()://变量是否为空 defined()://常量是否已经定义 define() array_key_exists(mixed key, array ...

  2. poj 2094 多项式求和。

    /** 给出多项式 p(x) = an*x^n + an-1*x^(n-1)..... + a1*x + a0; 给定n,l,k,m 计算 x 从 l到 l+k-1 的p(x)的后m 位的平方的和 用 ...

  3. C语言循环小技巧

    写代码,有两类追求,一种是追求实用(Coder),一种是追求代码艺术(Artist) 我是那种追实用追腻了,偶然追一下艺术(就是偶然和艺术有一腿)的那种Coder 很多人,已经习惯了for(i=0; ...

  4. glib 文档 代码 索引 编译

    ./configure --prefix=/opt/glib-2.28.8 --enable-staticmakemake install linux下载 WIN32下载 代码索引 文档索引 GLib ...

  5. 一个简单的基于canvas小游戏

    GDOI2016是我的退役战,不知道是题目画风不对,还是我自身的问题. 不过没关系啦,反正已经进过一次队OI生涯就没有什么遗憾的了. 这几天尝试着去做了个所谓的html5小游戏,略显简陋,但还是写个总 ...

  6. hdu4405概率dp入门

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. STL 源代码剖析 算法 stl_algo.h -- partition

    本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie partition ------------------------------------ ...

  8. 简单浮点数除法模拟-hdu-4493-Tutor

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4493 题目意思: 给小数点后两位的12个月的工资,求出平均工资,输出离小数点后第二位最近的两位小数, ...

  9. [week2]每周总结与工作计划

    这周总体过的还不错吧,没有颓废多少 = =... 果然有计划能够让效率提高,看了每周做个计划是很有益的. 这周前几天照例很忙,课比较多.后面几天每天早上都会安排下今天的计划,这样做起事来就有条理性多了 ...

  10. 嵌入式:nfs挂载开发板的几个陷阱

    1. host没有设置好,这个比较容易排查到. 开启portmap帮助网络应用程序找到正确的通讯端口: 开启nfs-kernel-server服务: 开启设置要export出去的服务目录. sudo ...