結果

問題 No.108 トリプルカードコンプ
ユーザー tkzw_21tkzw_21
提出日時 2014-12-23 16:53:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 894 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 74,104 KB
実行使用メモリ 11,800 KB
最終ジャッジ日時 2023-09-02 21:40:56
合計ジャッジ時間 1,907 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,540 KB
testcase_01 AC 5 ms
11,740 KB
testcase_02 AC 6 ms
11,524 KB
testcase_03 AC 6 ms
11,544 KB
testcase_04 AC 5 ms
11,536 KB
testcase_05 AC 5 ms
11,636 KB
testcase_06 AC 5 ms
11,524 KB
testcase_07 AC 9 ms
11,556 KB
testcase_08 AC 5 ms
11,544 KB
testcase_09 AC 5 ms
11,712 KB
testcase_10 AC 6 ms
11,512 KB
testcase_11 AC 6 ms
11,540 KB
testcase_12 AC 5 ms
11,672 KB
testcase_13 AC 6 ms
11,728 KB
testcase_14 AC 6 ms
11,640 KB
testcase_15 AC 6 ms
11,540 KB
testcase_16 AC 6 ms
11,768 KB
testcase_17 AC 5 ms
11,712 KB
testcase_18 AC 9 ms
11,532 KB
testcase_19 AC 6 ms
11,556 KB
testcase_20 AC 6 ms
11,532 KB
testcase_21 AC 7 ms
11,800 KB
testcase_22 AC 6 ms
11,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <list>
#include <algorithm>
#define INF 114514

using namespace std;

typedef pair<double,double> P;
int n;

double memo[101][101][101];
double dfs(int n3,int n2,int n1){
	if(memo[n3][n2][n1] >= 0)return memo[n3][n2][n1];

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

int main(void){
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin >> a[i];
	
	int n3,n2,n1;
	n3=n2=n1=0;
	for(int i=0;i<n;i++){
		if(a[i] == 0)n3++;
		if(a[i] == 1)n2++;
		if(a[i] == 2)n1++;
	}
	memset(memo,-1,sizeof(memo));
	memo[0][0][0] = 0;
	printf("%.12lf\n",dfs(n3,n2,n1));

	return 0;
}
0