結果

問題 No.108 トリプルカードコンプ
ユーザー ttkkggwwttkkggww
提出日時 2020-04-08 22:56:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,073 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 165,440 KB
実行使用メモリ 13,792 KB
最終ジャッジ日時 2023-09-26 11:07:25
合計ジャッジ時間 2,907 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 9 ms
13,656 KB
testcase_08 AC 6 ms
13,792 KB
testcase_09 AC 6 ms
13,628 KB
testcase_10 AC 6 ms
13,644 KB
testcase_11 AC 6 ms
13,628 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 4 ms
8,520 KB
testcase_14 AC 3 ms
8,588 KB
testcase_15 AC 4 ms
8,576 KB
testcase_16 AC 4 ms
8,548 KB
testcase_17 AC 3 ms
8,624 KB
testcase_18 AC 8 ms
13,576 KB
testcase_19 AC 6 ms
13,520 KB
testcase_20 AC 6 ms
13,608 KB
testcase_21 AC 7 ms
13,696 KB
testcase_22 AC 5 ms
13,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n;
double dp[110][110][110];
int cnt[4];

double rec(int x,int y,int z)
{//x一枚以上あるカードの種類
//y二枚以上あるカードの種類
//z三枚以上あるカードの種類
//それからコンプリートするために必要な回数の期待値

	if(dp[x][y][z]!=-1)return dp[x][y][z];
	dp[x][y][z] = 0;
	//z/nででないとき、でるまでの回数の期待値
	double exp_num = 1.0 * n/(n-z);
	//n-x ゼロ枚の数
	if(x!=n)dp[x][y][z] += (rec(x+1,y,z)+exp_num)*(n-x)/(n-z);
	//x-y一枚のすう
	if(y!=x)dp[x][y][z] += (rec(x,y+1,z)+exp_num)*(x-y)/(n-z);
	//y−z 二枚のすう
	if(z!=y)dp[x][y][z] += (rec(x,y,z+1)+exp_num)*(y-z)/(n-z);
	return dp[x][y][z];
}


int main()
{
	cin >> n;
	for(int i = 0;i<n+1;i++)for(int j = 0;j<n+1;++j)for(int k = 0;k <n+1;k++)dp[i][j][k] = -1;
	dp[n][n][n] = 0;
	for(int i = 0;i<n;i++)
	{
		int x;
		cin >> x;
		cnt[min(x,3)]++;
	}
	cnt[2] += cnt[3];
	cnt[1] += cnt[2];
	printf("%.12lf\n",rec(cnt[1],cnt[2],cnt[3]));
	return 0;
}

0