結果

問題 No.108 トリプルカードコンプ
ユーザー h_nosonh_noson
提出日時 2016-03-23 16:51:09
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 991 bytes
コンパイル時間 499 ms
コンパイル使用メモリ 67,640 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-10-01 21:32:28
合計ジャッジ時間 1,265 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

typedef long long ll;

double dp[101][101][101];
double n;

double e(int a, int b, int c) {
    if (dp[a][b][c] > 0)
        return dp[a][b][c];
    if (a+b+c > 0) {
        dp[a][b][c] = n;
        if (a > 0) dp[a][b][c] += e(a-1,b+1,c)*a;
        if (b > 0) dp[a][b][c] += e(a,b-1,c+1)*b;
        if (c > 0) dp[a][b][c] += e(a,b,c-1)*c;
        dp[a][b][c] /= a+b+c;
    }
    return dp[a][b][c];
}

int main() {
    int i, a, b, c;
    cin >> n;
    a = b = c = 0;
    rep (i,n) {
        int x;
        cin >> x;
        if (x == 0)
            a++;
        else if (x == 1)
            b++;
        else if (x == 2)
            c++;
    }
    cout << fixed << setprecision(7);
    cout << e(a,b,c) << endl;
    return 0;
}
0