結果

問題 No.108 トリプルカードコンプ
ユーザー ふーらくたるふーらくたる
提出日時 2016-09-24 00:34:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,132 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 63,736 KB
実行使用メモリ 14,040 KB
最終ジャッジ日時 2023-08-11 06:16:04
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,984 KB
testcase_01 AC 6 ms
13,992 KB
testcase_02 AC 6 ms
13,988 KB
testcase_03 AC 6 ms
13,936 KB
testcase_04 AC 6 ms
13,940 KB
testcase_05 AC 6 ms
13,912 KB
testcase_06 AC 6 ms
13,864 KB
testcase_07 AC 8 ms
13,812 KB
testcase_08 AC 6 ms
13,864 KB
testcase_09 AC 6 ms
13,932 KB
testcase_10 AC 6 ms
13,860 KB
testcase_11 AC 6 ms
13,856 KB
testcase_12 AC 6 ms
13,972 KB
testcase_13 AC 6 ms
13,972 KB
testcase_14 AC 6 ms
13,856 KB
testcase_15 AC 6 ms
14,036 KB
testcase_16 AC 6 ms
13,988 KB
testcase_17 AC 6 ms
13,988 KB
testcase_18 AC 8 ms
13,952 KB
testcase_19 AC 6 ms
13,864 KB
testcase_20 AC 6 ms
13,976 KB
testcase_21 AC 8 ms
14,040 KB
testcase_22 AC 6 ms
13,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
using namespace std;

const int MAX_N = 110;

double memo[MAX_N][MAX_N][MAX_N];

int n;

double calc(int n0, int n1, int n2) {
    if (memo[n0][n1][n2] >= 0.0) return memo[n0][n1][n2];
    int sum = n0 + n1 + n2;
    if (sum == 0) {
        return memo[n0][n1][n2] = 0.0;
    }
    double res = (double)n / (double)sum;
    if (n0 > 0) res += (double)n0 / (double)sum * calc(n0 - 1, n1 + 1, n2);
    if (n1 > 0) res += (double)n1 / (double)sum * calc(n0, n1 - 1, n2 + 1);
    if (n2 > 0) res += (double)n2 / (double)sum * calc(n0, n1, n2 - 1);
    return memo[n0][n1][n2] = res;
}

int main() {
    cin >> n;

    for (int n0 = 0; n0 < MAX_N; n0++) {
        for (int n1 = 0; n1 < MAX_N; n1++) {
            for (int n2 = 0; n2 < MAX_N; n2++) {
                memo[n0][n1][n2] = -1.0;
            }
        }
    }

    int n0 = 0, n1 = 0, n2 = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == 0) n0++;
        else if (a == 1) n1++;
        else if (a == 2) n2++;
    }
    cout << fixed << setprecision(10) << calc(n0, n1, n2) << endl;
    return 0;
}
0