uva 11181(条件概率)
来源:互联网 发布:通话软件实现原理 编辑:程序博客网 时间:2024/05/29 03:28
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
Problem-setter: Shahriar Manzoor
Special Thanks: Derek Kisman
直接根据条件概率的定义来
P(A|B) = P(AB)/P(B)
在这道题中B就是r个人买了东西
A就是某个人买了东西
然后考虑所有情况的概率,累加起来求的各个事件的概率
开始枚举所有的组合都不会写了,后来想想就是用类似dp的思想,dfs实现就好了,尼玛,智商拙计
#include <cstdio>double p[25],ans[25];int n,r,vis[25];void dfs(int k,int count){ if(count == r){ double tem = 1; for(int i = 1;i <= n;i++){ if(vis[i]) tem *= p[i]; else tem *= (1-p[i]); } ans[0] += tem; for(int i = 1;i <= n;i++) if(vis[i]) ans[i] += tem; } else{ for(int i = k+1;i <= n;i++){ vis[i] = 1; dfs(i,count+1); vis[i] = 0; } }}int main(){ int t=0; while(scanf("%d%d",&n,&r)){ if(n == 0 && r == 0) break; t++; printf("Case %d:\n",t); for(int i = 0;i < 25;i++){ ans[i] = 0; vis[i] = 0; } for(int i = 1;i <= n;i++) scanf("%lf",&p[i]); dfs(0,0); for(int i = 1;i <= n;i++) printf("%.6lf\n",ans[i]/ans[0]); } return 0;}
- uva 11181(条件概率)
- UVa 11181 条件概率
- uva 11181 条件概率
- 枚举,预处理,条件概率(条件概率,uva 11181)
- 【UVA】11181 - Probability|Given(条件概率)
- UVa 11181 - Probability|Given (条件概率)
- uva 11181 Probability|Given 条件概率
- UVA 11181(C) ——Probability|Given (条件概率, dfs求组合)
- 条件概率
- 条件概率
- 条件概率
- UVa 11181 - Probability|Given 概率
- UVA 11181 Probability|Given 概率
- UVA 11181(数学概率)
- uva 11181 概率与排列
- uva 11181 DFS+概率计算
- UVA.11181 Probability|Given (概率)
- 复合概率和条件概率
- 强烈推荐:240多个jQuery插件
- PHP+Ajax 用户名检测详解
- Linux下C++查找文件夹下的文件
- CodeIgniter 适配器
- qnx下实现ftp服务器和xp的通讯
- uva 11181(条件概率)
- linux下一个单进程并发服务器的实例 使用select
- 深入推荐引擎相关算法 - 协同过滤
- plsql导入导出各种数据库文件方法
- switch变量的作用 域问题
- UIWindow的一点儿思考
- android UI进阶之自定义组合控件
- PHPCMS v9 Getshell(Apache)
- js获取项目根路径