結果

問題 No.108 トリプルカードコンプ
ユーザー finefine
提出日時 2017-08-26 20:30:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 919 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 163,720 KB
実行使用メモリ 12,532 KB
最終ジャッジ日時 2024-04-23 17:19:56
合計ジャッジ時間 2,389 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 9 ms
12,476 KB
testcase_08 AC 4 ms
12,532 KB
testcase_09 AC 4 ms
12,416 KB
testcase_10 AC 5 ms
12,416 KB
testcase_11 AC 4 ms
12,416 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,888 KB
testcase_14 AC 2 ms
5,760 KB
testcase_15 AC 2 ms
5,760 KB
testcase_16 AC 4 ms
5,760 KB
testcase_17 AC 3 ms
5,504 KB
testcase_18 AC 7 ms
12,032 KB
testcase_19 AC 5 ms
11,520 KB
testcase_20 AC 4 ms
12,416 KB
testcase_21 AC 6 ms
12,288 KB
testcase_22 AC 3 ms
11,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int n;
double dp[105][105][105];

double solve(int cnt0, int cnt1, int cnt2) {
	if (cnt0 + cnt1 + cnt2 == 0) return 0;
	if (dp[cnt0][cnt1][cnt2] != -1) return dp[cnt0][cnt1][cnt2];
	double res = n - cnt0 - cnt1 - cnt2;
	if (cnt0 > 0) res += cnt0 * (solve(cnt0 - 1, cnt1 + 1, cnt2) + 1);
	if (cnt1 > 0) res += cnt1 * (solve(cnt0, cnt1 - 1, cnt2 + 1) + 1);
	if (cnt2 > 0) res += cnt2 * (solve(cnt0, cnt1, cnt2 - 1) + 1);
	res /= cnt0 + cnt1 + cnt2;
	return dp[cnt0][cnt1][cnt2] = res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	int cnt[3] = {};
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a < 3) cnt[a]++;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				dp[i][j][k] = -1;
			}
		}
	}
	cout << fixed << setprecision(10) << solve(cnt[0], cnt[1], cnt[2]) << endl;
	return 0;
}
0