枚举,条件概率。

2^20次方等于100w,是大约可以没准还能过的。

二进制枚举时,如果买东西的人恰好为r个,设概率为p,就将sum[i]+=p(sum[i]为r个人买东西时第i个人买东西的概率),tot+=p(tot为r个人买东西的概率)

要求的就是sum[i]/tot。

P(第i个人实际买东西)=P(r个人买东西且第i个人在其中)/P(r个人买东西)。

r为0时特判

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 20 + 10;
int n,r,N,cnt,kase;
double a[maxn],sum[maxn];
double tot,p; int main() {
kase=0;
while(scanf("%d%d",&n,&r)==2) {
printf("Case %d:\n",++kase);
if(!n&&!r) break;
for(int i=0;i<n;i++) scanf("%lf",&a[i]);
if(!r) {
for(int i=0;i<n;i++) printf("0.000000\n");
continue;
}
N=1<<n;
memset(sum,0,sizeof(sum)); tot=0;
for(int i=1;i<N;i++) {
cnt=0; p=1;
for(int j=0;j<n;j++) {
if(i&(1<<j)) {cnt++; p*=a[j];}
else p*=(1-a[j]);
}
if(cnt==r) {
for(int j=0;j<n;j++) if(i&(1<<j)) sum[j]+=p;
tot+=p;
}
}
for(int i=0;i<n;i++) printf("%.6lf\n",sum[i]/tot);
}
return 0;
}

uva11181Probability|Given的更多相关文章

  1. UVA11181Probability|Given(条件概率)

    题目链接 紫书P327 题意:有n个人准备去超市逛,其中第i个人买东西的概率是 Pi .逛完以后你得知有 r 个人买了东西.根据这一信息,计算每个人实际买东西的概率.输入 n ( 1 <= n ...

随机推荐

  1. tangent space /handness

    normal tangent bitangent 三者互相垂直. 组成一个tangent space 表示一个点 对于原本位置的偏移(扰动) 考虑到这是为了 normalmap做出虚假的normal来 ...

  2. 【.Net--资料】

    1.http://msdn.microsoft.com/zh-cn/dn338450 2..NET Technology Guidance http://www.microsoft.com/net/n ...

  3. mysql数据库主外键级联删除脚本RESTRICT --> CASCADE

    在项目中,我们一般在数据库设计的时候做主外键关联设计,要么就不做.但是这样不符合规范,呵呵. 建立主外键关系的时候,默认是不能级联删除的.而出现往往在删除主表的数据时报错, 需要先删除从表然后再删除主 ...

  4. POJ 1852

    #include <iostream> using namespace std; int main() { //freopen("acm.acm","r&qu ...

  5. Ubuntu环境下手动配置HBase0.94.25

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  6. hdu2015

    http://acm.hdu.edu.cn/showproblem.php?pid=2015 #include<iostream> #include<stdio.h> #inc ...

  7. hdu2013

    http://acm.hdu.edu.cn/showproblem.php?pid=2013 #include<iostream> #include<stdio.h> #inc ...

  8. 李洪强iOS开发之OC语言@property @synthesize和id

    OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字是编译器特性,让xcode可以自动生成getter和setter的声明 ...

  9. leetcode 5 :Longest Palindromic Substring 找出最长回文子串

    题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  10. Unity UGUI —— 无限循环List(转载)

    using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; ...