結果

問題 No.2364 Knapsack Problem
ユーザー rlangevinrlangevin
提出日時 2023-06-30 21:33:40
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 912 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 840,452 KB
最終ジャッジ日時 2023-09-21 15:22:21
合計ジャッジ時間 3,319 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
90,412 KB
testcase_01 AC 93 ms
90,368 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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()))
A = A + C
B = B + D

inf = 10 ** 18
N2 = 2 ** (N + M)
dp = [[-inf] * (W + 1) for i in range(1 << N2)]
dp[0][0] = 0
for s in range(N2):
    for w in range(W + 1):
        for i in range(N + M):
            if (s >> i) & 1:
                continue
            if i < N:
                if w + A[i] > W:
                    continue
                dp[s | (1 << i)][w + A[i]] = max(dp[s | (1 << i)][w + A[i]], dp[s][w] + B[i])
            else:
                if w - A[i] < 0:
                    continue
                dp[s | (1 << i)][w - A[i]] = max(dp[s | (1 << i)][w - A[i]], dp[s][w] - B[i])
                
ans = 0
for s in range(N2):
    for w in range(W + 1):
        ans = max(ans, dp[s][w])
        
print(ans)
        
0