結果

問題 No.108 トリプルカードコンプ
ユーザー furafura
提出日時 2020-06-07 16:18:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 709 bytes
コンパイル時間 2,646 ms
コンパイル使用メモリ 200,596 KB
実行使用メモリ 11,720 KB
最終ジャッジ日時 2023-08-25 11:00:40
合計ジャッジ時間 4,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 11 ms
11,616 KB
testcase_08 AC 5 ms
11,720 KB
testcase_09 AC 5 ms
11,716 KB
testcase_10 AC 5 ms
11,632 KB
testcase_11 AC 5 ms
11,532 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
6,712 KB
testcase_14 AC 3 ms
6,688 KB
testcase_15 AC 3 ms
6,624 KB
testcase_16 AC 3 ms
6,708 KB
testcase_17 AC 2 ms
6,624 KB
testcase_18 AC 9 ms
11,212 KB
testcase_19 AC 6 ms
11,284 KB
testcase_20 AC 6 ms
11,704 KB
testcase_21 AC 8 ms
11,508 KB
testcase_22 AC 5 ms
11,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n;
double memo[101][101][101];

double dfs(int n0,int n1,int n2,int n3){
	if(memo[n0][n1][n2]!=-1) return memo[n0][n1][n2];

	if(n3==n) return memo[n0][n1][n2]=0;

	double res=1;
	if(n0>0) res+=dfs(n0-1,n1+1,n2,n3)*n0/n;
	if(n1>0) res+=dfs(n0,n1-1,n2+1,n3)*n1/n;
	if(n2>0) res+=dfs(n0,n1,n2-1,n3+1)*n2/n;
	res/=1-1.0*n3/n;
	return memo[n0][n1][n2]=res;
}

int main(){
	scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]), a[i]=min(a[i],3);

	int freq[4]={};
	rep(i,n) freq[a[i]]++;

	rep(i,n+1) rep(j,n+1) rep(k,n+1) memo[i][j][k]=-1;
	printf("%.9f\n",dfs(freq[0],freq[1],freq[2],freq[3]));

	return 0;
}
0