結果
問題 |
No.108 トリプルカードコンプ
|
ユーザー |
![]() |
提出日時 | 2021-03-08 14:47:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 5,000 ms |
コード長 | 1,235 bytes |
コンパイル時間 | 1,227 ms |
コンパイル使用メモリ | 103,652 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-10-10 01:28:55 |
合計ジャッジ時間 | 2,245 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <iostream> #include <iomanip> //<<setprecision(12), or <<fixed #include <algorithm> #include <functional> #include <map> #include <vector> #include <queue> #include <cmath> #include <set> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; int main() { ll N; cin>>N; vector<ll> A(N); for(auto& a:A) cin>>a; vector<ll> num(4,0); for(auto& a:A) { num[max(0LL,3-a)]++; } //1,2,3 vector<vector<vector<double>>> dp(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1))); dp[0][0][0]=0; auto solve=[&](auto& solve, ll a, ll b, ll c) { if(dp[a][b][c]!=-1) return dp[a][b][c]; double res=0; if(a!=0) res+=(solve(solve,a-1,b,c)+1)*a/(double)(a+b+c); if(b!=0) res+=(solve(solve,a+1,b-1,c)+1)*b/(double)(a+b+c); if(c!=0) res+=(solve(solve,a,b+1,c-1)+1)*c/(double)(a+b+c); res+=(N/(double)(a+b+c)-1); dp[a][b][c]=res; //cout<<a<<" "<<b<<" "<<c<<" "<<res<<endl; return dp[a][b][c]; }; cout<<fixed<<setprecision(15)<<solve(solve,num[1],num[2],num[3])<<endl; // Fear misreading. return 0; }