結果
問題 | No.108 トリプルカードコンプ |
ユーザー | ふーらくたる |
提出日時 | 2016-09-24 00:34:46 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 9 ms / 5,000 ms |
コード長 | 1,132 bytes |
コンパイル時間 | 464 ms |
コンパイル使用メモリ | 63,200 KB |
実行使用メモリ | 14,172 KB |
最終ジャッジ日時 | 2024-11-17 20:15:00 |
合計ジャッジ時間 | 1,534 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <iostream> #include <iomanip> using namespace std; const int MAX_N = 110; double memo[MAX_N][MAX_N][MAX_N]; int n; double calc(int n0, int n1, int n2) { if (memo[n0][n1][n2] >= 0.0) return memo[n0][n1][n2]; int sum = n0 + n1 + n2; if (sum == 0) { return memo[n0][n1][n2] = 0.0; } double res = (double)n / (double)sum; if (n0 > 0) res += (double)n0 / (double)sum * calc(n0 - 1, n1 + 1, n2); if (n1 > 0) res += (double)n1 / (double)sum * calc(n0, n1 - 1, n2 + 1); if (n2 > 0) res += (double)n2 / (double)sum * calc(n0, n1, n2 - 1); return memo[n0][n1][n2] = res; } int main() { cin >> n; for (int n0 = 0; n0 < MAX_N; n0++) { for (int n1 = 0; n1 < MAX_N; n1++) { for (int n2 = 0; n2 < MAX_N; n2++) { memo[n0][n1][n2] = -1.0; } } } int n0 = 0, n1 = 0, n2 = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 0) n0++; else if (a == 1) n1++; else if (a == 2) n2++; } cout << fixed << setprecision(10) << calc(n0, n1, n2) << endl; return 0; }