結果
| 問題 | No.108 トリプルカードコンプ |
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-12-03 17:26:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 1,055 bytes |
| コンパイル時間 | 2,233 ms |
| コンパイル使用メモリ | 196,752 KB |
| 最終ジャッジ日時 | 2025-01-06 18:03:48 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct Precision{
Precision(){
cout<<fixed<<setprecision(12);
}
}precision_beet;
//INSERT ABOVE HERE
double dp[111][111][111];
signed main(){
Int n;
cin>>n;
vector<Int> a(n);
for(Int i=0;i<n;i++) cin>>a[i];
for(Int i=0;i<111;i++)
for(Int j=0;j<111;j++)
for(Int k=0;k<111;k++)
dp[i][j][k]=-1;
function<double(Int, Int, Int)> dfs=
[&](Int x,Int y,Int z)->double{
double &res=dp[x][y][z];
if(res>=0) return res;
if(x==0&&y==0&&z==0) return res=0;
res=1;
if(x) res+=dfs(x-1,y+1,z)*x/n;
if(y) res+=dfs(x,y-1,z+1)*y/n;
if(z) res+=dfs(x,y,z-1)*z/n;
res*=1.0*n/(x+y+z);
return res;
};
Int x=0,y=0,z=0;
for(Int i=0;i<n;i++){
if(a[i]==0) x++;
if(a[i]==1) y++;
if(a[i]==2) z++;
}
cout<<dfs(x,y,z)<<endl;
return 0;
}
beet