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. ViewFilpper

    package com.example.suneyaenews; import java.util.ArrayList; import java.util.HashMap; import java.u ...

  2. linux 进程通信

    IPC: 管道,FIFO,信号,消息队列(system v/ posix),共享内存(system v/  posix),socket 同步机制: 互斥锁,条件变量,记录上锁, 信号量(system ...

  3. 基于visual Studio2013解决C语言竞赛题之0202坐标转换

    题目

  4. BZOJ 1015

    program bzoj1015; {$inline on} ; type node=record togo,next:longint; end; var tot,n,m,d,cnt:longint; ...

  5. (3)选择元素——(4)css选择器(CSS selectors)

    The jQuery library supports nearly all of the selectors included in CSS specifications 1 through 3, ...

  6. android 中的 ViewPager+ Fragment

    android的Viewpager 的各种经常的用法,朋友问我要过,所以就稍微总结一下, ViewPager + Fragment 经常用到  代码是从   actionbarsherlock 中提取 ...

  7. as3声谱效果,有在线演示地址,能够播放本地音乐

    来源:潮汕IT男 简单的as3声谱效果,能够播放本地音乐. tag=as3" style="word-wrap:break-word; margin:0px; padding:0p ...

  8. 写了交互给后台后来不能用?bug多多多又找不到文件效率低?工作流程帮你优化起来~~~~

    前端工作流程(多方交互篇) 新的网页: 1.跟美工沟通,跟产品沟通,跟后台沟通.前两者主要是页面样式.后者主要是表单交互.用哪个框架之类的. 2.实现.(写清楚哪块是用什么验证方式的)→ 给后台. 3 ...

  9. java中将list、map对象写入文件

    链接地址:http://blog.sina.com.cn/s/blog_4a4f9fb50101p6jv.html     推荐:凤爪女瓜子男怪象该谁反思伦敦房价为什么持续暴涨 × wvqusrtg个 ...

  10. Oracle同义词 synonyms

    Oracle中的同义词: 总结:简单的一句话,Oracle中不同用户的表一般都只能够自己的所属的用户可以用,如果不想通过授权的方式授权给其他用户使用,那么创建表的时候在表名的前面加上 synonyms ...