結果

問題 No.108 トリプルカードコンプ
ユーザー ぴろずぴろず
提出日時 2014-12-22 09:10:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 5,337 ms
コンパイル使用メモリ 78,532 KB
実行使用メモリ 65,376 KB
最終ジャッジ日時 2023-09-02 21:26:22
合計ジャッジ時間 8,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,680 KB
testcase_01 AC 127 ms
55,776 KB
testcase_02 AC 125 ms
55,752 KB
testcase_03 AC 125 ms
55,804 KB
testcase_04 AC 124 ms
55,964 KB
testcase_05 AC 126 ms
55,856 KB
testcase_06 AC 127 ms
55,464 KB
testcase_07 AC 165 ms
65,292 KB
testcase_08 AC 152 ms
64,984 KB
testcase_09 AC 141 ms
64,520 KB
testcase_10 AC 142 ms
64,708 KB
testcase_11 AC 142 ms
64,604 KB
testcase_12 AC 127 ms
55,948 KB
testcase_13 AC 138 ms
56,012 KB
testcase_14 AC 142 ms
56,388 KB
testcase_15 AC 130 ms
56,028 KB
testcase_16 AC 139 ms
56,012 KB
testcase_17 AC 130 ms
55,336 KB
testcase_18 AC 164 ms
64,852 KB
testcase_19 AC 158 ms
65,000 KB
testcase_20 AC 150 ms
64,524 KB
testcase_21 AC 157 ms
64,744 KB
testcase_22 AC 152 ms
65,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no108;

import java.util.Scanner;

public class Main {
	static int n;
	static int[] a;
	static double[][][] dp;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[3];
		for(int i=0;i<n;i++) {
			int b = sc.nextInt();
			if (b < 3) {
				a[b]++;
			}
		}
		dp = new double[n+1][n+1][n+1];
		System.out.println(dfs(a[0],a[1],a[2]));
	}
	static double dfs(int n0,int n1,int n2) {
		if (n0 == 0 && n1 == 0 && n2 == 0) {
			return 0;
		}
		if (dp[n0][n1][n2] != 0) {
			return dp[n0][n1][n2];
		}
		double ret = 1;
		if (n0 > 0) {
			ret += dfs(n0-1,n1+1,n2) * ((double) n0/n);
		}
		if (n1 > 0) {
			ret += dfs(n0,n1-1,n2+1) * ((double) n1/n);
		}
		if (n2 > 0) {
			ret += dfs(n0,n1,n2-1) * ((double) n2/n);
		}
		return dp[n0][n1][n2] = ret / ((double) (n0 + n1 + n2) / n);
	}

}
0