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. C# Programming Study #2

    readonly (C# Reference) readonly  关键字是可以在字段上使用的修饰符.  当字段声明包括 readonly 修饰符时,该声明引入的字段赋值只能作为声明的一部分出现,或者 ...

  3. C语言之六大排序算法

    排序算法 1.直接插入排序 直接插入排序是将原始数据依次从已排好序的序列的最右侧比较起,若小于则向前插,一直插到合适的位置即可. 源代码如下: #include<stdio.h> void ...

  4. CSS3 transform制作的漂亮的滚动式导航

    模拟这个做的 不过实现的没有别人那么好 http://www.creativetier.com/products/modern-menu-3/vertical.html 关于transform  看这 ...

  5. Week14(12月9日)

    Part I:提问 =========================== 1.ASP.NET MVC围绕事件驱动的页面声明周期而建立,在渲染的页面上可以触发事件. 2.ASP.NET MVC脱离了H ...

  6. Windows Azure 社区新闻综述(#76 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 ·   更新 Windows Azure 中的 SQ ...

  7. 字符编码终极笔记:ASCII、Unicode、UTF-8、UTF-16、UCS、BOM、Endian

    1.字符编码.内码,顺带介绍汉字编码 字符必须编码后才能被计算机处理.计算机使用的缺省编码方式就是计算机的内码.早期的计算机使用7位的ASCII编码,为了处理汉字,程序员设计了用于简体中文的GB231 ...

  8. SQL Server 2008 还原数据库

    1.得到数据库备份文件,怎么得到的,[能够看这里]~ 2.把备份文件加个.bak 的后缀,比如: 3.打开SQL , 你能够新建一个空数据库 , 或者利用原有的数据库 , 点击右键>>任务 ...

  9. 【LeetCode】【Python题解】Single Number &amp; Maximum Depth of Binary Tree

    今天做了三道LeetCode上的简单题目,每道题都是用c++和Python两种语言写的.由于c++版的代码网上比較多.所以就仅仅分享一下Python的代码吧,刚学完Python的基本的语法,做做Lee ...

  10. 同时支持多家云平台的管理工具HybridFox

    偶然间发现了这个firefox上的开元插件 号称支持AWS,Eucalyptus,OpenStack,OpenNebula 目的是通过一个入口实现异种云平台的管理 主要功能包括: Manage Ima ...