dfs构造n个人r个人买东西的概率作为分母 每次构造成功时给选中的人加上对应的概率就可以了
#include<cstdio>
#include<algorithm>
#include<cstring>
#define SF scanf
#define PF printf
using namespace std;
const int MAXN = 20;
int n, r, Num[MAXN+10];
double P[MAXN+10], A[MAXN+10], tot;
bool vis[MAXN+10];
void deal()
{
double p = 1.0;
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= r; i++) vis[Num[i]] = true, p *= P[Num[i]];
for(int i = 1; i <= n; i++) if(!vis[i]) p *= (1 - P[i]);
for(int i = 1; i <= r; i++) A[Num[i]] += p;
tot += p;
}
void dfs(int cur, int res)
{
if(res > r) { deal(); return ; }
for(int i = cur+1; i <= n; i++)
{
if(r - res > n - i) break;
Num[res] = i;
dfs(i, res+1);
}
}
int main()
{
int kase = 0;
while(SF("%d%d", &n, &r) == 2 && n + r)
{
memset(A, 0, sizeof(A));
for(int i = 1; i <= n; i++) SF("%lf", &P[i]);
tot = 0;
dfs(0, 1);
PF("Case %d:\n", ++kase);
for(int i = 1; i <= n; i++) PF("%lf\n", A[i] / tot);
}
}