//UVA11181Probability|Given
#include<cstdio>
#include<cstring>
const int maxn = 20 + 5;
double P[maxn], sum[maxn];
int N, r, buy[maxn];
void dfs(int d, int cnt, double possible) {
if(cnt > r || d - cnt > N - r) return ;
if(d == N) {//上面的语句隐含了cnt==r的条件
sum[N] += possible;
for(int i = 0; i < N; i++) if(buy[i]) sum[i] += possible;
return ;
}//全概率公式
buy[d] = 0;
dfs(d + 1, cnt, possible * (1.0 - P[d]));
buy[d] = 1;
dfs(d + 1, cnt + 1, possible * P[d]);
}
int main() {
int kase = 0;
while(scanf("%d%d", &N, &r) == 2 && N) {
memset(sum, 0, sizeof(sum));
for(int i = 0; i < N; i++) scanf("%lf", &P[i]);
dfs(0, 0, 1.0);
printf("Case %d:\n", ++kase);
for(int i = 0; i < N; i++) printf("%.6lf\n", sum[i] / sum[N]);
}
return 0;
}
/*
3 2
0.10
0.20
0.30
5 1
0.10
0.10
0.10
0.10
0.10
0 0
*/
UVA11181Probability|Given
最新推荐文章于 2019-05-03 09:48:24 发布