結果
| 問題 | No.108 トリプルカードコンプ |
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2020-01-20 16:03:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 1,271 bytes |
| コンパイル時間 | 2,127 ms |
| コンパイル使用メモリ | 178,492 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2024-07-02 22:32:33 |
| 合計ジャッジ時間 | 2,863 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
for (auto &e : t) fill(e, v);
}
// auto v = make_vec<int>(h, w);
// fill(v, 0);
signed main(){
int n; cin >> n;
vector<int> a(n), cnt(4, 0);
for(int i = 0; i < n; i++){
cin >> a[i];
cnt[min(3LL, a[i])]++;
}
auto dp = make_vec<double>(n+1, n+1, n+1);
fill(dp, -1);
dp[0][0][0] = 0;
function< double(int,int,int) > rec =
[&](int a, int b, int c){
if(dp[a][b][c] != -1) return dp[a][b][c];
double E = 1.0 * n / (a + b + c);
if(a > 0) E += rec(a-1, b+1, c) * a / (a + b + c);
if(b > 0) E += rec(a, b-1, c+1) * b / (a + b + c);
if(c > 0) E += rec(a, b, c-1) * c / (a + b + c);
return dp[a][b][c] = E;
};
printf("%.9f\n",rec(cnt[0], cnt[1], cnt[2]));
return 0;
}
oxyshower