//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
*/
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交