結果

問題 No.108 トリプルカードコンプ
ユーザー HachimoriHachimori
提出日時 2014-12-21 23:54:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 1,072 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 75,460 KB
実行使用メモリ 22,820 KB
最終ジャッジ日時 2023-09-02 21:04:30
合計ジャッジ時間 2,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 246 ms
22,820 KB
testcase_08 AC 5 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 13 ms
5,020 KB
testcase_14 AC 6 ms
4,368 KB
testcase_15 AC 3 ms
4,368 KB
testcase_16 AC 9 ms
4,572 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 175 ms
17,832 KB
testcase_19 AC 48 ms
8,068 KB
testcase_20 AC 18 ms
5,392 KB
testcase_21 AC 114 ms
13,312 KB
testcase_22 AC 4 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
#include<numeric>
#include<cstdio>
using namespace std;

int nType, totalCard;
vector<int> init;

void read() {
    init = vector<int>(4, 0);
    
    cin >> nType;
    for (int i = 0; i < nType; ++i) {
        int cnt;
        cin >> cnt;
        ++init[min(3, cnt)];
    }
    
    totalCard = accumulate(init.begin(), init.end(), 0);
}


double rec(vector<int> &num2cnt, map<vector<int>, double> &dp) {
    if (num2cnt[3] == nType) return 0;
    if (dp.count(num2cnt)) return dp[num2cnt];
    double sum = 1;
    
    for (int i = 0; i < 3; ++i) {
        if (num2cnt[i] > 0) {
            double mul = 1.0 * num2cnt[i] / totalCard;
            --num2cnt[i];
            ++num2cnt[i + 1];
            sum += rec(num2cnt, dp) * mul;
            ++num2cnt[i];
            --num2cnt[i + 1];
        }
    }

    return dp[num2cnt] = sum / (1 - 1.0 * num2cnt[3] / totalCard);
}


void work() {
    map<vector<int>, double> dp;
    printf("%.10lf\n", rec(init, dp));
}


int main() {
    read();
    work();
    return 0;
}
0