結果
問題 |
No.108 トリプルカードコンプ
|
ユーザー |
![]() |
提出日時 | 2020-03-21 07:09:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 5,000 ms |
コード長 | 1,273 bytes |
コンパイル時間 | 2,308 ms |
コンパイル使用メモリ | 176,620 KB |
実行使用メモリ | 16,000 KB |
最終ジャッジ日時 | 2024-12-17 18:44:25 |
合計ジャッジ時間 | 3,250 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() #define ln '\n' constexpr long long MOD = 1000000007LL; //constexpr long long MOD = 998244353LL; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long long, long long> pll; template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; } template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// #define EPS (1e-10) int N; double dp[300][300][300]; double func(int a, int b, int c) { if (a+b+c==0) return 0; if (dp[a][b][c] > EPS) return dp[a][b][c]; dp[a][b][c] = N; if (a) dp[a][b][c] += func(a-1,b+1,c)*a; if (b) dp[a][b][c] += func(a,b-1,c+1)*b; if (c) dp[a][b][c] += func(a,b,c-1)*c; dp[a][b][c] /= (a+b+c); return dp[a][b][c]; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; int a = 0, b = 0, c = 0; rep(i,N) { int A; cin >> A; if (A==0) a++; if (A==1) b++; if (A==2) c++; } cout << fixed << setprecision(10) << func(a,b,c) << ln; }