UVA 11181 Probability|Given 概率


全概率......


  条件概率,贝叶斯公式,全概率.....


Time Limit: 3000MSMemory Limit: Unknown64bit IO Format: %lld & %llu

Submit Status

Description

Download as PDF

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

Source

Root :: AOAPC II: Beginning Algorithm Contests (Second Edition) (Rujia Liu) :: Chapter 10. Maths ::  Examples
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) ::  Volume 6. Mathematical Concepts and Methods
Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Probability ::  Exercises: Beginner
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics ::  Probability Theory
Root :: Prominent Problemsetters ::  Shahriar Manzoor
Root :: Competitive Programming: Increasing the Lower Bound of Programming Contests (Steven & Felix Halim) :: Chapter 5. Mathematics ::  Probability Theory

Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Probability Theory ::  Standard

Submit Status



#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

int n,r;
double p[50];
double ans[50];

int cot(int x)
{
    int ret=0;
    while(x)
    {
        x=x&(x-1);
        ret++;
    }
    return ret;
}

int main()
{
    int cas=1;
    while(scanf("%d%d",&n,&r)!=EOF)
    {
        if(n==0&&r==0) break;
        for(int i=0;i<n;i++)
            scanf("%lf",p+i);
        memset(ans,0,sizeof(ans));
        double all=0.0;
        for(int i=0;i<(1<<n);i++)
        {
            if(cot(i)==r)
            {
                double ppp=1.;
                for(int j=0;j<n;j++)
                {
                    if(i&(1<<j)) ppp*=p[j];
                    else ppp*=(1-p[j]);
                }
                all+=ppp;
                for(int j=0;j<n;j++)
                {
                    if(i&(1<<j)) ans[j]+=ppp;
                }
            }
        }
        printf("Case %d:\n",cas++);
        for(int i=0;i<n;i++)
        {
            printf("%.6lf\n",ans[i]/all);
        }
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
顺序概率比测试(Sequential Probability Ratio Test,SPRT)是一种用于统计假设检验的方法。这种方法可以帮助我们在一个序列中逐步获取更多的数据,并根据这些数据来判断统计假设。 SPRT的基本思想是,在统计推断中,我们需要根据样本数据来判断某个假设的可行性。然而,如果我们仅仅依赖一次采样数据来进行判断,可能会存在较大的误差。因此,SPRT的核心在于逐步地获取更多的数据,并使用概率比的方法来进行判断。 在进行SPRT时,我们需要设定两个极限。一个是接受(accept)假设的下限,另一个是拒绝(reject)假设的上限。然后,我们开始进行实验并收集数据。在每一步实验中,我们计算当前数据下的概率比,并与两个极限进行比较。如果概率比超过拒绝上限,我们就可以拒绝假设;如果概率比低于接受下限,我们就可以接受假设。如果概率比在两个极限之间,我们继续进行下一步实验。 SPRT的优势在于它可以灵活地根据数据来调整判断过程,减少了对大量数据的需求,从而提高了判断的效率。然而,它也有一些限制。首先,需要事先设定接受和拒绝的极限,这可能会对判断结果产生影响。另外,SPRT要求数据之间是独立同分布的,这在实际应用中可能会有一定的限制。 总之,顺序概率比测试是一种用于统计假设检验的方法,通过逐步获取更多的数据并使用概率比进行判断,可以提高检验的效率。在实际应用中,我们需要根据具体情况来设定极限并注意数据的独立同分布性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值