結果

問題 No.108 トリプルカードコンプ
ユーザー kusainu7kusainu7
提出日時 2021-05-29 19:08:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 705 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 72,188 KB
実行使用メモリ 13,892 KB
最終ジャッジ日時 2024-04-25 14:59:49
合計ジャッジ時間 1,369 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 14 ms
13,892 KB
testcase_08 AC 13 ms
13,152 KB
testcase_09 AC 14 ms
13,292 KB
testcase_10 AC 14 ms
13,376 KB
testcase_11 AC 14 ms
13,492 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 4 ms
8,140 KB
testcase_14 AC 4 ms
8,392 KB
testcase_15 AC 4 ms
8,136 KB
testcase_16 AC 3 ms
8,140 KB
testcase_17 AC 4 ms
8,008 KB
testcase_18 AC 13 ms
12,744 KB
testcase_19 AC 12 ms
13,004 KB
testcase_20 AC 13 ms
13,084 KB
testcase_21 AC 14 ms
13,892 KB
testcase_22 AC 13 ms
13,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

double c[110][110][110] = {};

void dp(int n, int *a) {
	c[n][n][n] = 0;
	for (int i=n; i>=0; i--) {
		for (int j=n; j>=0; j--) {
			for (int k=n; k>=0; k--) {
				if (k>=n) {
					continue;
				}
				c[i][j][k] = 1.0*n/(n-k);
				if (i!=n) c[i][j][k] += c[i+1][j][k]*(n-i)/(n-k);
				if (i!=j) c[i][j][k] += c[i][j+1][k]*(i-j)/(n-k);
				if (j!=k) c[i][j][k] += c[i][j][k+1]*(j-k)/(n-k);
			}
		}
	}
}

int main() {
	int n, x;
	cin >> n;
	int a[4] = {};

	for (int i=0; i<n; i++) {
		cin >> x;
		if (x>3) {
			a[3]++;
		} else if (x!=0) {
			a[x]++;
		}
	}
	
	for (int i=2; i>0; i--) {
		a[i] += a[i+1];
	}
	
	dp(n, a);

	printf("%.10f\n", c[a[1]][a[2]][a[3]]);
}
0