結果

問題 No.2364 Knapsack Problem
ユーザー tassei903tassei903
提出日時 2023-06-30 21:29:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 3,000 ms
コード長 556 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 76,784 KB
最終ジャッジ日時 2023-09-21 15:17:20
合計ジャッジ時間 3,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,248 KB
testcase_01 AC 70 ms
71,136 KB
testcase_02 AC 69 ms
71,248 KB
testcase_03 AC 70 ms
71,376 KB
testcase_04 AC 80 ms
70,996 KB
testcase_05 AC 71 ms
71,252 KB
testcase_06 AC 71 ms
71,168 KB
testcase_07 AC 87 ms
76,632 KB
testcase_08 AC 70 ms
71,216 KB
testcase_09 AC 82 ms
76,640 KB
testcase_10 AC 84 ms
76,428 KB
testcase_11 AC 70 ms
71,376 KB
testcase_12 AC 86 ms
76,532 KB
testcase_13 AC 86 ms
76,652 KB
testcase_14 AC 83 ms
76,740 KB
testcase_15 AC 87 ms
76,784 KB
testcase_16 AC 85 ms
76,644 KB
testcase_17 AC 83 ms
76,408 KB
testcase_18 AC 85 ms
76,524 KB
testcase_19 AC 85 ms
76,596 KB
testcase_20 AC 87 ms
76,624 KB
testcase_21 AC 87 ms
76,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, W = map(int, input().split())
N = n + m
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))

e = a + [-i for i in c]
f = b + [-i for i in d]

dp = [None for i in range(1<<N)]
dp[0] = (0, 0)
ans = 0
for i in range(1<<N):
    if dp[i] == None:
        continue
    w, v = dp[i]
    ans = max(ans, v)
    for j in range(N):
        if i >> j & 1:
            continue
        if 0 <= w + e[j] <= W:
            dp[i | (1<<j)] = (w + e[j], v + f[j])

print(ans)
0