結果

問題 No.108 トリプルカードコンプ
ユーザー nemakura3nemakura3
提出日時 2019-08-08 19:40:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 165,464 KB
実行使用メモリ 14,064 KB
最終ジャッジ日時 2023-09-26 01:30:53
合計ジャッジ時間 2,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,916 KB
testcase_01 AC 5 ms
14,020 KB
testcase_02 AC 6 ms
14,016 KB
testcase_03 AC 5 ms
13,900 KB
testcase_04 AC 5 ms
13,908 KB
testcase_05 AC 6 ms
14,012 KB
testcase_06 AC 5 ms
13,876 KB
testcase_07 AC 9 ms
13,916 KB
testcase_08 AC 5 ms
13,864 KB
testcase_09 AC 5 ms
13,896 KB
testcase_10 AC 5 ms
13,848 KB
testcase_11 AC 5 ms
13,988 KB
testcase_12 WA -
testcase_13 AC 6 ms
13,916 KB
testcase_14 AC 6 ms
14,008 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 5 ms
13,872 KB
testcase_18 AC 9 ms
14,064 KB
testcase_19 AC 6 ms
13,908 KB
testcase_20 AC 6 ms
14,024 KB
testcase_21 AC 7 ms
14,060 KB
testcase_22 AC 5 ms
14,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for (int (i) = (a); (i) < (b); ++(i))
#define rrep(i,a,b) for (int (i) = (a); (i) >= (b); --(i))
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1LL << 60;
const ll MOD = 1e9 + 7;

template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
int c0, c1, c2;
double dp[110][110][110];

double dfs(int i, int j, int k) {
	if (dp[i][j][k] >= 0) return dp[i][j][k];
	if (i == 0 && j == 0 && k == 0) return 0;

	double res = N;
	if (i > 0) res += dfs(i - 1, j + 1, k) * i;
	if (j > 0) res += dfs(i, j - 1, k + 1) * j;
	if (k > 0) res += dfs(i, j, k - 1) * k;
	res /= (double)(i + j + k);
	return dp[i][j][k] = res;
}

int main() {
	cin >> N;
	rep(i, 0, N) {
		int a;
		cin >> a;
		if (a == 0) ++c0;
		if (a == 1) ++c1;
		if (a == 2) ++c2;
	}

	memset(dp, -1, sizeof(dp));

	cout << dfs(c0, c1, c2) << endl;
	return 0;
}
0