結果

問題 No.2364 Knapsack Problem
ユーザー yabityabit
提出日時 2023-06-30 23:34:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 613 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 76,876 KB
最終ジャッジ日時 2023-09-21 17:50:27
合計ジャッジ時間 3,248 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,052 KB
testcase_01 AC 67 ms
71,264 KB
testcase_02 AC 71 ms
71,268 KB
testcase_03 AC 68 ms
71,256 KB
testcase_04 AC 68 ms
71,336 KB
testcase_05 AC 68 ms
71,432 KB
testcase_06 AC 69 ms
71,444 KB
testcase_07 AC 96 ms
76,628 KB
testcase_08 AC 69 ms
71,336 KB
testcase_09 AC 87 ms
76,872 KB
testcase_10 AC 90 ms
76,816 KB
testcase_11 AC 70 ms
71,272 KB
testcase_12 AC 89 ms
76,848 KB
testcase_13 AC 86 ms
76,648 KB
testcase_14 AC 88 ms
76,532 KB
testcase_15 AC 89 ms
76,576 KB
testcase_16 AC 91 ms
76,500 KB
testcase_17 AC 91 ms
76,468 KB
testcase_18 AC 87 ms
76,852 KB
testcase_19 AC 91 ms
76,860 KB
testcase_20 AC 89 ms
76,716 KB
testcase_21 AC 88 ms
76,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, W = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
Weight = A + [-c for c in C]
Value = B + [-d for d in D]
nm = N + M
dp = [-(10**9)] * 2**nm
dp[0] = 0
ans = 0
for i in range(2**nm):
    if dp[i] == -(10**9):
        continue
    w = 0
    for j in range(nm):
        if i >> j & 1:
            w += Weight[j]
    for j in range(nm):
        if i >> j & 1:
            continue
        if 0 <= w+Weight[j] <= W:
            dp[i|1<<j] = max(dp[i|1<<j],dp[i]+Value[j])

print(max(dp))
0