結果

問題 No.108 トリプルカードコンプ
ユーザー A BenznessA Benzness
提出日時 2023-06-26 13:53:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,236 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 67,896 KB
実行使用メモリ 13,860 KB
最終ジャッジ日時 2023-09-16 07:22:32
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 10 ms
13,708 KB
testcase_08 AC 6 ms
13,652 KB
testcase_09 AC 6 ms
13,860 KB
testcase_10 AC 6 ms
13,816 KB
testcase_11 AC 6 ms
13,636 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
8,744 KB
testcase_14 AC 4 ms
8,520 KB
testcase_15 AC 3 ms
8,536 KB
testcase_16 AC 3 ms
8,556 KB
testcase_17 AC 3 ms
8,536 KB
testcase_18 AC 8 ms
13,572 KB
testcase_19 AC 6 ms
13,656 KB
testcase_20 AC 6 ms
13,612 KB
testcase_21 AC 8 ms
13,740 KB
testcase_22 AC 5 ms
13,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <math.h>

/**
8
3 4 5 6 7 8 9 10
 */

int N;
double dp[110][110][110];
int cnt[4];

double solve(int x, int y, int z) {
  // memoization
  if (dp[x][y][z] != -1) return dp[x][y][z];
  dp[x][y][z] = 0;

  // 2枚以下しかもっていないものが出るまで
  // 引く回数の期待値
  double exp_num = 1.0 * N / (N - z);

  // (条件付き期待値) * (条件付き確率) の足しあわせ
  if (x != N) {
    double d = solve(x+1, y, z);
    dp[x][y][z] += (d + exp_num) * (N - x) / (N - z);
  }
  if (y != x) {
    double d = solve(x, y+1, z);
    dp[x][y][z] += (d + exp_num) * (x - y) / (N - z);
  }
  if (z != y) {
    double d = solve(x, y, z+1);
    dp[x][y][z] += (d + exp_num) * (y - z) / (N - z);
  }

  return dp[x][y][z];
}

int main() {
  std::cin >> N;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      for (int k = 0; k <= N; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
  dp[N][N][N] = 0;

  for (int i = 0; i < N; i++) {
    int A; std::cin >> A;
    cnt[std::min(A, 3)]++;
  }

  for (int i = 2; i > 0; i--) {
    cnt[i] += cnt[i + 1];
  }

  double doub = solve(cnt[1], cnt[2], cnt[3]);
  printf("%.12f\n", doub);
  return 0;
}
0