感受
又被卡精度了,看来要理解出题组的意思。
两种求法,求解每一道题解出的概率
求解完之后,就愉快地dfs
#include <bits/stdc++.h> using namespace std; typedef long long ll; double p[15]; double ans[15], a[15], b[15], c[15]; double solve(double a, double b, double c){ return 1.0 - (1.0 - a) * (1.0 - b) * (1.0 - c); //return a + (1.0 - a) * b + (1.0 - a) * c - (1.0 - a) * b * c;被卡精度了 } void dfs(int k, double tmp, int rig_num){ if(k == 13){ ans[rig_num] += tmp; return ; } dfs(k + 1, tmp * p[k], rig_num + 1); dfs(k + 1, tmp * (1.0 - p[k]), rig_num); } int main(){ for(int i = 1; i <= 12; i++){ scanf("%lf", &a[i]); } for(int i = 1; i <= 12; i++){ scanf("%lf", &b[i]); } for(int i = 1; i <= 12; i++){ scanf("%lf", &c[i]); } for(int i = 1; i <= 12; i++){ p[i] = solve(a[i], b[i], c[i]); } dfs(1, 1.0, 0); for(int i = 0; i <= 12; i++){ printf("%.6f\n", ans[i]); } return 0; }