結果
| 問題 | No.108 トリプルカードコンプ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-21 23:54:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 221 ms / 5,000 ms |
| コード長 | 1,072 bytes |
| コンパイル時間 | 595 ms |
| コンパイル使用メモリ | 74,872 KB |
| 実行使用メモリ | 22,784 KB |
| 最終ジャッジ日時 | 2024-06-12 03:22:59 |
| 合計ジャッジ時間 | 1,894 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include<iostream>
#include<vector>
#include<map>
#include<numeric>
#include<cstdio>
using namespace std;
int nType, totalCard;
vector<int> init;
void read() {
init = vector<int>(4, 0);
cin >> nType;
for (int i = 0; i < nType; ++i) {
int cnt;
cin >> cnt;
++init[min(3, cnt)];
}
totalCard = accumulate(init.begin(), init.end(), 0);
}
double rec(vector<int> &num2cnt, map<vector<int>, double> &dp) {
if (num2cnt[3] == nType) return 0;
if (dp.count(num2cnt)) return dp[num2cnt];
double sum = 1;
for (int i = 0; i < 3; ++i) {
if (num2cnt[i] > 0) {
double mul = 1.0 * num2cnt[i] / totalCard;
--num2cnt[i];
++num2cnt[i + 1];
sum += rec(num2cnt, dp) * mul;
++num2cnt[i];
--num2cnt[i + 1];
}
}
return dp[num2cnt] = sum / (1 - 1.0 * num2cnt[3] / totalCard);
}
void work() {
map<vector<int>, double> dp;
printf("%.10lf\n", rec(init, dp));
}
int main() {
read();
work();
return 0;
}