結果

問題 No.108 トリプルカードコンプ
ユーザー なお
提出日時 2014-12-21 23:53:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 809 bytes
コンパイル時間 1,579 ms
コンパイル使用メモリ 157,940 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-06-12 03:22:12
合計ジャッジ時間 7,857 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
const int MOD = 1000000007;

int k[4];

double dfs(int N, int k0, int k1, int k2, int k3, int cnt){
    if(k0 == 0 && k1 == 0 && k2 == 0) return 0;
    if(cnt>100) return 0;

    double res = 1;
    if(k0 > 0) res += dfs(N, k0-1, k1+1, k2,   k3    , cnt+1) * k0 / N;
    if(k1 > 0) res += dfs(N, k0,   k1-1, k2+1, k3    , cnt+1) * k1 / N;
    if(k2 > 0) res += dfs(N, k0,   k1,   k2-1, k3 + 1, cnt+1) * k2 / N;
    if(k3 > 0) res += dfs(N, k0,   k1,   k2,   k3    , cnt+1) * k3 / N;
    return res;
}

int main(){
    int N; cin >> N;
    REP(i,N){
        int A; cin >> A;
        if(A < 3) k[A]++;
    }

    cout << dfs(N, k[0],k[1],k[2],N-k[0]-k[1]-k[2],0) << endl;
    return 0;
}
0