結果
| 問題 | No.108 トリプルカードコンプ |
| コンテスト | |
| ユーザー |
yuusti
|
| 提出日時 | 2015-01-22 19:05:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 733 bytes |
| コンパイル時間 | 391 ms |
| コンパイル使用メモリ | 55,548 KB |
| 実行使用メモリ | 14,140 KB |
| 最終ジャッジ日時 | 2024-06-23 00:20:58 |
| 合計ジャッジ時間 | 1,437 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <iostream>
using namespace std;
const int N = 110;
double dp[N][N][N];
int n;
double rec(int a, int b, int c){
if (a + b + c == 0) return 0;
double &res = dp[a][b][c];
if (res >= -.5) return res;
double dn = n;
res = 1;
if (a) res += a / dn*rec(a - 1, b + 1, c);
if (b) res += b / dn*rec(a, b - 1, c + 1);
if (c) res += c / dn*rec(a, b, c - 1);
return res *= dn / (a + b + c);
}
int main(){
cout.setf(ios::fixed);
cout.precision(100);
cin >> n;
int cnt[3] = {};
for (int i = 0; i < n; ++i){
int x;
cin >> x;
if (x <= 2) ++cnt[x];
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
dp[i][j][k] = -1;
cout << rec(cnt[0], cnt[1], cnt[2]) << endl;
}
yuusti