結果

問題 No.108 トリプルカードコンプ
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-14 17:03:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 787 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 165,576 KB
実行使用メモリ 8,252 KB
最終ジャッジ日時 2023-10-13 14:49:32
合計ジャッジ時間 2,723 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 12 ms
8,252 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 9 ms
6,612 KB
testcase_19 AC 4 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 6 ms
4,980 KB
testcase_22 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N;
double memo[110][110][110];

double dfs(int a, int b, int c) {
    if (memo[a][b][c])
        return memo[a][b][c];
    if (a + b + c == 0)
        return 0;
    double ret = 0;
    if (a > 0)
        ret += dfs(a - 1, b + 1, c) * a / N;
    if (b > 0)
        ret += dfs(a, b - 1, c + 1) * b / N;
    if (c > 0)
        ret += dfs(a, b, c - 1) * c / N;
    ret += 1;
    ret *= (double)N / (a + b + c);
    return memo[a][b][c] = ret;
}

int main() {
    int A[110];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int cnt[3] = {};
    for (int i = 0; i < N; i++) {
        if (A[i] < 3)
            cnt[A[i]]++;
    }

    cout << fixed << setprecision(10) << dfs(cnt[0], cnt[1], cnt[2]) << endl;
}
0