結果

問題 No.108 トリプルカードコンプ
ユーザー uenokuuenoku
提出日時 2020-04-28 20:54:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,640 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 167,948 KB
実行使用メモリ 12,264 KB
最終ジャッジ日時 2023-08-16 18:01:00
合計ジャッジ時間 2,869 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 8 ms
12,088 KB
testcase_08 AC 3 ms
12,096 KB
testcase_09 AC 4 ms
12,264 KB
testcase_10 AC 4 ms
12,104 KB
testcase_11 AC 5 ms
12,080 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
6,668 KB
testcase_14 AC 2 ms
6,600 KB
testcase_15 AC 2 ms
6,496 KB
testcase_16 AC 3 ms
6,720 KB
testcase_17 AC 2 ms
6,620 KB
testcase_18 AC 6 ms
11,780 KB
testcase_19 AC 5 ms
11,608 KB
testcase_20 AC 4 ms
12,012 KB
testcase_21 AC 6 ms
12,112 KB
testcase_22 AC 3 ms
11,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
double dp[105][105][105] = {};
int n;
double calc(int zero, int one, int two)
{
    double &ret = dp[zero][one][two];
    if (ret > 0)
        return ret;
    if (zero == 0 && one == 0 && two == 0)
        return 0;
    ret = 1;
    double p0 = double(zero) / double(n);
    double p1 = double(one) / double(n);
    double p2 = double(two) / double(n);
    double p3 = double(n - zero - one - two) / double(n);
    if (zero)
        ret += calc(zero - 1, one + 1, two) * p0;
    if (one)
        ret += calc(zero, one - 1, two + 1) * p1;
    if (two)
        ret += calc(zero, one, two - 1) * p2;
    ret /= (1 - p3);
    return ret;
}
int main()
{
    cin >> n;
    vector<int> a(n);
    vector<int> c(3);
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] < 3)
        {
            c[a[i]]++;
        }
    }
    rep(i, n) rep(j, n) rep(k, n)
    {
        dp[i][j][k] = -1;
    }
    double ret = calc(c[0], c[1], c[2]);
    printf("%.10f\n", ret);
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
    return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
    return (l < r) ? (l = r, true) : false;
}
0