文章目录
4.26比赛
题目大意:给出12道题做出的概率,问做出0-12道题目的概率
/*
4.26 比赛 :https://ac.nowcoder.com/acm/problem/14734
对于每一个题目要么做出,要么做不出,利用dfs进行判断即可
// 还有一种dp做法,未完待续......
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 15;
double a[N], b[N], c[N], un[N];
double ans;
void dfs(int pos, int now, int need, double p)
{
if(pos == 13) // 当所有题目都写完了
{
if(now == need) { // 达到了需要
ans += p;
}
return ;
} // 判断该题做不做出来
if(now < need )
dfs(pos + 1, now + 1, need, p * (1 - un[pos]));
dfs(pos + 1, now, need, p * un[pos]);
}
int main()
{
for (int i = 1; i <= 12; ++i) cin >> a[i];
for (int i = 1; i <= 12; ++i) cin >> b[i];
for (int i = 1; i <= 12; ++i) cin >> c[i];
// 一道题做不出来:自己做不出,没听到左边也没听到右边
for (int i = 1; i <= 12; ++i) un[i] = (1-a[i]) * (1-b[i]) * (1-c[i]);
for (int i = 1; i <= 13; ++i)
{
ans = 0;
dfs(1, 0, i - 1, 1);
printf("%.6f\n", ans);
}
return 0;
}