結果

問題 No.108 トリプルカードコンプ
ユーザー roaris
提出日時 2019-11-09 01:41:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 165,828 KB
実行使用メモリ 14,176 KB
最終ジャッジ日時 2024-09-15 03:48:24
合計ジャッジ時間 2,986 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

double rec(int i, int j, int k) {
    if (memo[i][j][k] >= 0) return memo[i][j][k];
     
    double res = 0;
    
    if (i > 0) res += i*rec(i-1, j+1, k);
    if (j > 0) res += j*rec(i, j-1, k+1);
    if (k > 0) res += k*rec(i, j, k-1);
    res += N;
    res /= i+j+k;
    
    return memo[i][j][k] = res;
}

signed main() {
    cin >> N;
    int zero=0, one=0, two=0;
    
    for (int i=0; i<N; i++) {
        int ai; cin >> ai;
        
        if (ai == 0) zero++;
        else if (ai == 1) one++;
        else if (ai == 2) two++;
    }
    
    memset(memo, -1, sizeof(memo));
    memo[0][0][0] = 0;
    
    cout << rec(zero, one, two) << endl;
}
0