結果

問題 No.108 トリプルカードコンプ
ユーザー roiti46roiti46
提出日時 2015-02-25 16:27:48
言語 Python2
(2.7.18)
結果
AC  
実行時間 306 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 6,700 KB
実行使用メモリ 19,248 KB
最終ジャッジ日時 2023-09-06 04:30:33
合計ジャッジ時間 3,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
14,624 KB
testcase_01 AC 39 ms
14,708 KB
testcase_02 AC 39 ms
14,668 KB
testcase_03 AC 40 ms
14,684 KB
testcase_04 AC 40 ms
14,600 KB
testcase_05 AC 40 ms
14,804 KB
testcase_06 AC 40 ms
14,620 KB
testcase_07 AC 306 ms
19,248 KB
testcase_08 AC 45 ms
14,992 KB
testcase_09 AC 40 ms
14,736 KB
testcase_10 AC 39 ms
14,604 KB
testcase_11 AC 39 ms
14,832 KB
testcase_12 AC 40 ms
14,620 KB
testcase_13 AC 59 ms
15,324 KB
testcase_14 AC 48 ms
15,144 KB
testcase_15 AC 43 ms
14,648 KB
testcase_16 AC 52 ms
15,040 KB
testcase_17 AC 39 ms
14,804 KB
testcase_18 AC 230 ms
18,076 KB
testcase_19 AC 103 ms
15,864 KB
testcase_20 AC 66 ms
15,448 KB
testcase_21 AC 170 ms
17,024 KB
testcase_22 AC 44 ms
15,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dp(n1,n2,n3):
    if memo[n1][n2][n3] > -1: return memo[n1][n2][n3]
    
    n123 = n1+n2+n3
    memo[n1][n2][n3] = N*1.0/n123
    if n1 > 0: memo[n1][n2][n3] += dp(n1-1,n2  ,n3  )*n1/n123
    if n2 > 0: memo[n1][n2][n3] += dp(n1+1,n2-1,n3  )*n2/n123
    if n3 > 0: memo[n1][n2][n3] += dp(n1  ,n2+1,n3-1)*n3/n123
    return memo[n1][n2][n3]
    
N = int(raw_input())
A = map(int,raw_input().split())
memo = [[[-1]*101 for i in xrange(101)] for j in xrange(101)]
memo[0][0][0] = 0.0
need = [0]*3
for a in A:
    if a == 0: need[2] += 1
    if a == 1: need[1] += 1
    if a == 2: need[0] += 1
print dp(*need)
0