結果

問題 No.1688 Veterinarian
ユーザー simansiman
提出日時 2022-06-08 07:27:12
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 3,000 ms
コード長 1,519 bytes
コンパイル時間 3,510 ms
コンパイル使用メモリ 131,208 KB
実行使用メモリ 5,768 KB
最終ジャッジ日時 2023-10-21 03:59:49
合計ジャッジ時間 3,429 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 4 ms
5,768 KB
testcase_08 AC 50 ms
5,768 KB
testcase_09 AC 50 ms
5,648 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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