結果

問題 No.1688 Veterinarian
ユーザー siman
提出日時 2022-06-08 07:27:12
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 3,000 ms
コード長 1,519 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 139,536 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-21 05:03:32
合計ジャッジ時間 2,632 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int A, B, C, N;
  cin >> A >> B >> C >> N;

  double dp[A + 1][B + 1][C + 1];
  memset(dp, 0, sizeof(dp));
  dp[A][B][C] = 1.0;

  for (int i = 0; i < N; ++i) {
    double tmp[A + 1][B + 1][C + 1];
    memset(tmp, 0, sizeof(tmp));

    for (int a = 1; a <= A; ++a) {
      for (int b = 1; b <= B; ++b) {
        for (int c = 1; c <= C; ++c) {
          int S = a + b + c;

          double pa = a * (a - 1) * 1.0 / (S * (S - 1));
          double pb = b * (b - 1) * 1.0 / (S * (S - 1));
          double pc = c * (c - 1) * 1.0 / (S * (S - 1));

          tmp[a - 1][b][c] += pa * dp[a][b][c];
          tmp[a][b - 1][c] += pb * dp[a][b][c];
          tmp[a][b][c - 1] += pc * dp[a][b][c];
          tmp[a][b][c] += (1.0 - pa - pb - pc) * dp[a][b][c];
        }
      }
    }

    memcpy(dp, tmp, sizeof(tmp));
  }

  double ans[3] = {0.0, 0.0, 0.0};

  for (int a = 1; a <= A; ++a) {
    for (int b = 1; b <= B; ++b) {
      for (int c = 1; c <= C; ++c) {
        int da = A - a;
        int db = B - b;
        int dc = C - c;

        ans[0] += da * dp[a][b][c];
        ans[1] += db * dp[a][b][c];
        ans[2] += dc * dp[a][b][c];
      }
    }
  }

  cout << fixed << setprecision(10) << ans[0] << " " << ans[1] << " " << ans[2] << endl;

  return 0;
}
0