結果

問題 No.108 トリプルカードコンプ
ユーザー 👑 kmjpkmjp
提出日時 2014-12-21 23:25:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,277 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 145,588 KB
実行使用メモリ 11,728 KB
最終ジャッジ日時 2023-09-02 20:57:39
合計ジャッジ時間 3,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,516 KB
testcase_01 AC 5 ms
11,628 KB
testcase_02 AC 5 ms
11,680 KB
testcase_03 AC 5 ms
11,624 KB
testcase_04 AC 6 ms
11,516 KB
testcase_05 AC 6 ms
11,480 KB
testcase_06 AC 6 ms
11,464 KB
testcase_07 AC 10 ms
11,520 KB
testcase_08 AC 6 ms
11,668 KB
testcase_09 AC 6 ms
11,640 KB
testcase_10 AC 5 ms
11,728 KB
testcase_11 AC 5 ms
11,640 KB
testcase_12 AC 5 ms
11,640 KB
testcase_13 AC 6 ms
11,700 KB
testcase_14 AC 6 ms
11,524 KB
testcase_15 AC 5 ms
11,464 KB
testcase_16 AC 6 ms
11,512 KB
testcase_17 AC 6 ms
11,684 KB
testcase_18 AC 9 ms
11,492 KB
testcase_19 AC 7 ms
11,520 KB
testcase_20 AC 6 ms
11,704 KB
testcase_21 AC 7 ms
11,644 KB
testcase_22 AC 5 ms
11,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,NN[3];
int A[101];

double memo[101][101][101];

double dpdp(int n3,int n2,int n1) {
	if(memo[n3][n2][n1]>=0) return memo[n3][n2][n1];
	
	memo[n3][n2][n1]=N*1.0/(n1+n2+n3);
	if(n1>0) memo[n3][n2][n1]+=dpdp(n3,n2,n1-1)*n1/(n1+n2+n3);
	if(n2>0) memo[n3][n2][n1]+=dpdp(n3,n2-1,n1+1)*n2/(n1+n2+n3);
	if(n3>0) memo[n3][n2][n1]+=dpdp(n3-1,n2+1,n1)*n3/(n1+n2+n3);
	return memo[n3][n2][n1];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	cin>>N;
	
	FOR(i,N) {
		cin>>A[i];
		if(A[i]==0) NN[2]++;
		if(A[i]==1) NN[1]++;
		if(A[i]==2) NN[0]++;
	}
	FOR(x,101) FOR(y,101) FOR(i,101) memo[x][y][i]=-1;
	memo[0][0][0]=0;
	
	
	_P("%.12lf\n",dpdp(NN[2],NN[1],NN[0]));
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0