結果

問題 No.108 トリプルカードコンプ
ユーザー kagamizkagamiz
提出日時 2015-12-06 17:55:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 827 bytes
コンパイル時間 1,135 ms
コンパイル使用メモリ 144,040 KB
実行使用メモリ 20,132 KB
最終ジャッジ日時 2023-10-12 17:28:25
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,960 KB
testcase_01 AC 7 ms
19,960 KB
testcase_02 AC 8 ms
19,960 KB
testcase_03 AC 7 ms
19,960 KB
testcase_04 AC 8 ms
19,960 KB
testcase_05 AC 8 ms
19,904 KB
testcase_06 AC 7 ms
19,832 KB
testcase_07 AC 11 ms
19,952 KB
testcase_08 AC 8 ms
19,852 KB
testcase_09 AC 7 ms
20,080 KB
testcase_10 AC 8 ms
19,916 KB
testcase_11 AC 7 ms
19,828 KB
testcase_12 AC 7 ms
19,916 KB
testcase_13 AC 8 ms
19,924 KB
testcase_14 AC 7 ms
19,836 KB
testcase_15 AC 7 ms
19,952 KB
testcase_16 AC 7 ms
19,964 KB
testcase_17 AC 7 ms
19,840 KB
testcase_18 AC 9 ms
19,924 KB
testcase_19 AC 8 ms
20,132 KB
testcase_20 AC 8 ms
19,920 KB
testcase_21 AC 9 ms
19,840 KB
testcase_22 AC 7 ms
19,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int N;
double memo[128][128][128];

double calc(int zero, int one, int two)
{
	if (zero + one + two == 0) return (0);
	if (memo[zero][one][two] >= 0) return (memo[zero][one][two]);

	double ret = 1;
	if (zero) ret += zero * 1. / N * calc(zero - 1, one + 1, two);
	if (one)  ret += one  * 1. / N * calc(zero, one - 1, two + 1);
	if (two)  ret += two  * 1. / N * calc(zero, one, two - 1);
	
	ret *= N * 1. / (zero + one + two);

	return (memo[zero][one][two] = ret);
}

int main()
{
	int ct[3] = {0};

	scanf("%d", &N);

	for (int i = 0; i < N; i++){
		int x;
		scanf("%d", &x);
		if (x < 3) ct[x]++;
	}

	for (int i = 0; i < 128; i++) for (int j = 0; j < 128; j++) for (int k = 0; k < 128; k++) memo[i][j][k] = -1;

	printf("%.10lf\n", calc(ct[0], ct[1], ct[2]));

	return (0);
}
0