Uva 11181 Probability|Given(概率dp)
来源:互联网 发布:中指数据试用 编辑:程序博客网 时间:2024/05/22 13:23
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
题意:有n个人,并且知道每个人买东西的概率,现在已知有r个人买了东西,依次求第i个人买东西的概率
思路:ans[i]保存有r个人买了东西的情况下并且第i个人买了东西的概率,all代表n给人中第r个买了东西的概率
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<set>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define eps 1e-8//typedef __int64 ll;#define fre(i,a,b) for(i = a; i <b; i++)#define free(i,b,a) for(i = b; i >= a;i--)#define mem(t, v) memset ((t) , v, sizeof(t))#define ssf(n) scanf("%s", n)#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define bug pf("Hi\n")using namespace std;#define INF 0x3f3f3f3f#define N 25double ans[N];double p[N];int n,r;double dfs(int pos,int left,double pp){ if(pos>n) return left==0 ? pp : 0; double sum=0; if(left){ sum+=dfs(pos+1,left-1,pp*p[pos]); ans[pos]+=sum;} sum+=dfs(pos+1,left,pp*(1-p[pos])); return sum;}int main(){int i,j,ca=0; while(sff(n,r),n+r){fre(i,1,n+1) scanf("%lf",&p[i]);memset(ans,0,sizeof(ans)); double all=dfs(1,r,1); pf("Case %d:\n",++ca); for(i=1;i<=n;i++)pf("%.6lf\n",ans[i]/all);} return 0;}
- Uva 11181 Probability|Given(概率dp)
- Probability|Given - UVa 11181 概率dp
- uva 11181 - Probability|Given(概率)
- UVA 11181 - Probability|Given (概率DFS)
- 【UVA】11181 - Probability|Given(条件概率)
- UVA-11181 Probability|Given(概率)
- UVa 11181 - Probability|Given 概率
- UVA 11181 Probability|Given 概率
- UVA.11181 Probability|Given (概率)
- UVa 11181 - Probability|Given (条件概率)
- uva 11181 Probability|Given 条件概率
- uva 11181 Probability|Given
- Probability Given, UVa 11181
- Uva 11181 - Probability|Given
- UVA 11181 Probability|Given
- UVa 11181 Probability|Given
- Uva--11181--Probability|Given
- uva 11181 Probability|Given
- 习题3-7
- 自定义指示器 快速实现 ViewPager 滑动页卡切换(可用作整个 app上导航)
- HTTP请求头详解
- 释郴萌缘挖推帐显闭押妆共删臀萌陨本倨乘纳
- Mysql 独享表空间
- Uva 11181 Probability|Given(概率dp)
- HTML5 - video标签和audio标签
- 《当我们谈论爱情时,我们谈论机器》感悟一二
- uva 10131 Is Bigger Smarter? dag 最长路 加路径还原
- C# Asp.net MVC 分页时传参场景 动态生成QueryString
- 一个http请求的详细过程
- 几种图像处理库的研究
- Log4Net使用指南
- 设置本地wamp环境挂载多站点同时运行