题意

一共12道题,你有 的概率做对第 题,有 的概率抄到左边的,有 的概率抄到右边的,问做对 题的概率是多少。

solution

做对的概率不太好求,可以反过来求做错的概率,即 ,然后 表示前 道题做对 道的概率,设 ,得到状态转移方程:

Code

#include <bits/stdc++.h>
using namespace std;
double a[15], b[15], c[15], dp[15][15];
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];
  dp[0][0] = 1;
  for (int i = 1; i <= 12; i++) {
    dp[i][0] = dp[i - 1][0] * (1 - a[i]) * (1 - b[i]) * (1 - c[i]);
    for (int j = 1; j <= i; j++) {
      double wa = (1 - a[i]) * (1 - b[i]) * (1 - c[i]);
      dp[i][j] = dp[i - 1][j - 1] * (1 - wa) + dp[i - 1][j] * wa;
    }
  }
  for (int i = 0; i <= 12; i++) printf("%f\n", dp[12][i]);
  return 0;
}