結果
| 問題 | No.108 トリプルカードコンプ |
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2018-03-19 10:27:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 2,176 bytes |
| 記録 | |
| コンパイル時間 | 1,648 ms |
| コンパイル使用メモリ | 166,756 KB |
| 実行使用メモリ | 12,640 KB |
| 最終ジャッジ日時 | 2024-12-31 10:37:53 |
| 合計ジャッジ時間 | 2,760 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N;
double dp[101][101][101];
int vis[101][101][101];
//---------------------------------------------------------------------------------------------------
double f(int c0, int c1, int c2) {
if (vis[c0][c1][c2]) return dp[c0][c1][c2];
int n = c0 + c1 + c2;
if (!n) return 0;
double ex = (double)N / (double)n;
double res = 0;
if (c0) res += (f(c0 - 1, c1 + 1, c2) + ex) * c0 / n;
if (c1) res += (f(c0, c1 - 1, c2 + 1) + ex) * c1 / n;
if (c2) res += (f(c0, c1, c2 - 1) + ex) * c2 / n;
vis[c0][c1][c2] = 1;
return dp[c0][c1][c2] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
int c0 = 0, c1 = 0, c2 = 0;
rep(i, 0, N) {
int a; cin >> a;
if (a == 0) c0++;
else if (a == 1) c1++;
else if (a == 2) c2++;
}
double ans = f(c0, c1, c2);
printf("%.10f\n", ans);
}
はまやんはまやん