結果

問題 No.108 トリプルカードコンプ
ユーザー A BenznessA Benzness
提出日時 2023-06-26 14:02:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 68,136 KB
実行使用メモリ 13,904 KB
最終ジャッジ日時 2023-09-16 07:33:53
合計ジャッジ時間 1,850 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 10 ms
13,728 KB
testcase_08 AC 6 ms
13,624 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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[3];

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;
    if (A >= 3) A = 2;
    cnt[A - 1]++;
  }

  cnt[1] += cnt[2];
  cnt[0] += cnt[2];

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