結果

問題 No.1151 チャレンジゲーム
ユーザー aaaaaaaaaa2230
提出日時 2020-08-16 22:20:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 81,436 KB
最終ジャッジ日時 2024-10-11 10:44:32
合計ジャッジ時間 9,349 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split()))

count = [0]*(1<<n)
for i in range(1<<n):
    for j in range(n):
        if i>>j & 1:
            count[i] += a[j]

d = {}

def cal(s,t):
    if t <= 0:
        return 1
    if s == 0:
        return 0
    sta = s+ (t<<n)
    h = count[s]
    if sta in d:
        return d[sta]
    now = 0
    for i in range(n):
        if not s>>i & 1:
            continue
        nf = s^(1<<i)
        sco = 1
        for j in range(n):
            if not s>>j & 1:
                continue
            ns = s^(1<<j)
            p,q = 1/a[i],1/a[j]
            x,y = 1-cal(nf,h+1-t),cal(ns,t)
            v = (p*x+(1-p)*q*y)/(p+q-p*q)
            sco = min(sco,v)
        now = max(sco,now)
    d[sta] = now
    return now
print(cal((1<<n)-1,sum(a)//2+1))
0