結果

問題 No.108 トリプルカードコンプ
ユーザー yuustiyuusti
提出日時 2015-01-22 19:05:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 53,064 KB
実行使用メモリ 14,112 KB
最終ジャッジ日時 2023-09-05 03:37:12
合計ジャッジ時間 2,225 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,868 KB
testcase_01 AC 6 ms
13,928 KB
testcase_02 AC 5 ms
13,924 KB
testcase_03 AC 5 ms
14,040 KB
testcase_04 AC 5 ms
14,008 KB
testcase_05 AC 5 ms
13,924 KB
testcase_06 AC 6 ms
13,944 KB
testcase_07 AC 10 ms
14,096 KB
testcase_08 AC 6 ms
14,084 KB
testcase_09 AC 5 ms
13,944 KB
testcase_10 AC 6 ms
13,928 KB
testcase_11 AC 6 ms
14,112 KB
testcase_12 AC 6 ms
14,024 KB
testcase_13 AC 6 ms
13,928 KB
testcase_14 AC 6 ms
13,936 KB
testcase_15 AC 5 ms
14,044 KB
testcase_16 AC 6 ms
14,088 KB
testcase_17 AC 5 ms
14,008 KB
testcase_18 AC 8 ms
13,952 KB
testcase_19 AC 6 ms
14,100 KB
testcase_20 AC 6 ms
13,948 KB
testcase_21 AC 8 ms
14,104 KB
testcase_22 AC 6 ms
13,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

const int N = 110;
double dp[N][N][N];

int n;
double rec(int a, int b, int c){
	if (a + b + c == 0) return 0;

	double &res = dp[a][b][c];
	if (res >= -.5) return res;

	double dn = n;

	res = 1;
	if (a) res += a / dn*rec(a - 1, b + 1, c);
	if (b) res += b / dn*rec(a, b - 1, c + 1);
	if (c) res += c / dn*rec(a, b, c - 1);

	return res *= dn / (a + b + c);
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(100);

	cin >> n;
	int cnt[3] = {};
	for (int i = 0; i < n; ++i){
		int x;
		cin >> x;
		if (x <= 2) ++cnt[x];
	}

	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 << rec(cnt[0], cnt[1], cnt[2]) << endl;
}
0