solution
先考虑对于如何求出解出第道题的概率。直接求并不好求,但是解不出第道题的概率很好求,就是。那么解出第到题的概率就是。
因为题目数量非常小。所以可以枚举每道题是否解出来了,然后统计一下每种情况的概率,记录到答案里面即可。
code
/* * @Author: wxyww * @Date: 2020-05-18 14:04:38 * @Last Modified time: 2020-05-18 14:08:27 */ #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<ctime> #include<cmath> using namespace std; typedef long long ll; const int N = 20; ll read() { ll x = 0,f = 1;char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } double ans[N],pre[N]; int main() { int n = 12; for(int i = 1;i <= n;++i) { double x; scanf("%lf",&x); ans[i] = 1 - x; } for(int k = 1;k <= 2;++k) { for(int i = 1;i <= n;++i) { double x; scanf("%lf",&x); ans[i] = ans[i] * (1 - x); } } for(int i = 0;i < (1 << n);++i) { int cnt = 0;double k = 1.0; for(int j = 0;j < n;++j) { if((i >> j) & 1) { cnt++; k = k * (1 - ans[j + 1]); } else k = k * ans[j + 1]; } pre[cnt] += k; } for(int i = 0;i <= n;++i) printf("%.6lf\n",pre[i]); return 0; }