結果

問題 No.107 モンスター
ユーザー nebukuro09nebukuro09
提出日時 2016-10-04 17:13:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 3,561 ms / 5,000 ms
コード長 490 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 6,636 KB
実行使用メモリ 109,952 KB
最終ジャッジ日時 2023-08-23 06:55:06
合計ジャッジ時間 14,924 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,004 KB
testcase_01 AC 11 ms
6,052 KB
testcase_02 AC 11 ms
5,976 KB
testcase_03 AC 11 ms
5,968 KB
testcase_04 AC 12 ms
6,116 KB
testcase_05 AC 12 ms
6,112 KB
testcase_06 AC 11 ms
6,232 KB
testcase_07 AC 11 ms
6,088 KB
testcase_08 AC 12 ms
6,000 KB
testcase_09 AC 11 ms
6,056 KB
testcase_10 AC 11 ms
5,976 KB
testcase_11 AC 11 ms
6,000 KB
testcase_12 AC 11 ms
6,016 KB
testcase_13 AC 162 ms
12,040 KB
testcase_14 AC 601 ms
25,488 KB
testcase_15 AC 601 ms
25,616 KB
testcase_16 AC 12 ms
6,072 KB
testcase_17 AC 133 ms
11,996 KB
testcase_18 AC 30 ms
6,556 KB
testcase_19 AC 31 ms
6,640 KB
testcase_20 AC 3,561 ms
109,952 KB
testcase_21 AC 1,341 ms
51,472 KB
testcase_22 AC 3,164 ms
89,140 KB
testcase_23 AC 2,063 ms
83,316 KB
testcase_24 AC 1,548 ms
50,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = input()
D = map(int, raw_input().split())
done = 2**N-1

mem = {}
def rec(b, hp, maxhp):
    if (b, hp) in mem:
        return mem[(b, hp)]
    if b == done:
        return hp
    m = 0
    for i in xrange(N):
        if (1<<i) & b:
            continue
        if D[i] > 0:
            m = max(m, rec(b+(1<<i), min(hp+D[i], maxhp), maxhp))
        elif hp + D[i] > 0:
            m = max(m, rec(b+(1<<i), hp+D[i], maxhp+100))

    mem[(b, hp)] = m
    return m

print rec(0, 100, 100)
0