結果

問題 No.108 トリプルカードコンプ
ユーザー pekempeypekempey
提出日時 2015-08-21 11:08:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 1,270 ms
コンパイル使用メモリ 145,684 KB
実行使用メモリ 11,764 KB
最終ジャッジ日時 2023-09-25 14:14:23
合計ジャッジ時間 2,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,480 KB
testcase_01 AC 6 ms
11,536 KB
testcase_02 AC 5 ms
11,668 KB
testcase_03 AC 6 ms
11,672 KB
testcase_04 AC 5 ms
11,532 KB
testcase_05 AC 6 ms
11,764 KB
testcase_06 AC 5 ms
11,548 KB
testcase_07 AC 10 ms
11,500 KB
testcase_08 AC 6 ms
11,544 KB
testcase_09 AC 6 ms
11,660 KB
testcase_10 AC 6 ms
11,492 KB
testcase_11 AC 6 ms
11,636 KB
testcase_12 AC 5 ms
11,496 KB
testcase_13 AC 6 ms
11,660 KB
testcase_14 AC 6 ms
11,540 KB
testcase_15 AC 6 ms
11,548 KB
testcase_16 AC 6 ms
11,504 KB
testcase_17 AC 6 ms
11,636 KB
testcase_18 AC 9 ms
11,676 KB
testcase_19 AC 7 ms
11,680 KB
testcase_20 AC 6 ms
11,664 KB
testcase_21 AC 7 ms
11,544 KB
testcase_22 AC 5 ms
11,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

int N;
double memo[101][101][101]; // num 0, num 1, num 2

double E(int n0, int n1, int n2) {
	if (n0 == 0 && n1 == 0 && n2 == 0) return 0;
	if (memo[n0][n1][n2] >= 0) return memo[n0][n1][n2];
	int n3 = N - n0 - n1 - n2;
	double res = (double)n3 / N;
	if (n0 > 0) res += (E(n0 - 1, n1 + 1, n2) + 1) * ((double)n0 / N);
	if (n1 > 0) res += (E(n0, n1 - 1, n2 + 1) + 1) * ((double)n1 / N);
	if (n2 > 0) res += (E(n0, n1, n2 - 1) + 1) * ((double)n2 / N);
	res /= 1 - (double)n3 / N;

	return memo[n0][n1][n2] = res;
}

int main() {
	cin >> N;
	vector<int> A(N), num(4);
	rep (i, N) {
		cin >> A[i];
		A[i] = min(3, A[i]);
		num[A[i]]++;
	}
	fill_n((double *)memo, sizeof(memo) / sizeof(memo[0][0][0]), -1);

	double ans = E(num[0], num[1], num[2]);
	printf("%.20f\n", ans);

    return 0;
}
0