UVA 11181 Possibility Given

#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
int n,r;
double sum[21];
double R[21];
bool a[21];
double total;
void dfs(int i,int now,double p)
{
    if(i==n)
    {
        if(now==r)
        {
            total+=p;
            for(int i=0;i<n;i++)
                if(a[i])sum[i]+=p;
        }
        return;
    }
    a[i]=0;
    dfs(i+1,now,p*(1-R[i]));
    a[i]=1;
    dfs(i+1,now+1,p*R[i]);
}
int id=1;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif // ONLIN
    while(cin>>n>>r)
    {
        total=0;memset(sum,0,sizeof(sum));
        if(!n&&!r)break;
        for(int i=0;i<n;i++)cin>>R[i];
        dfs(0,0,1);
        printf("Case %d:\n",id++);
        for(int i=0;i<n;i++)printf("%.6f\n",sum[i]/total);
    }
}

 

posted @ 2018-08-23 13:21  erge1998  阅读(69)  评论(0编辑  收藏  举报