結果

問題 No.2364 Knapsack Problem
ユーザー lloyzlloyz
提出日時 2023-06-30 21:37:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 271 ms / 3,000 ms
コード長 898 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 143,012 KB
最終ジャッジ日時 2023-09-21 15:29:47
合計ジャッジ時間 4,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,032 KB
testcase_01 AC 69 ms
71,240 KB
testcase_02 AC 74 ms
75,928 KB
testcase_03 AC 75 ms
75,700 KB
testcase_04 AC 80 ms
76,416 KB
testcase_05 AC 82 ms
76,548 KB
testcase_06 AC 79 ms
76,112 KB
testcase_07 AC 121 ms
82,816 KB
testcase_08 AC 76 ms
75,716 KB
testcase_09 AC 114 ms
84,332 KB
testcase_10 AC 104 ms
79,072 KB
testcase_11 AC 80 ms
76,036 KB
testcase_12 AC 265 ms
142,904 KB
testcase_13 AC 262 ms
143,012 KB
testcase_14 AC 262 ms
142,720 KB
testcase_15 AC 268 ms
142,884 KB
testcase_16 AC 263 ms
142,680 KB
testcase_17 AC 263 ms
142,568 KB
testcase_18 AC 266 ms
142,788 KB
testcase_19 AC 271 ms
142,640 KB
testcase_20 AC 264 ms
142,520 KB
testcase_21 AC 259 ms
142,536 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()))

INF = 10**18
V = [[-INF for _ in range(w + 1)] for _ in range(1 << (n + m))]
V[0][0] = 0
ans = 0
for bit in range(1 << (n + m)):
    for ww in range(w + 1):
        if V[bit][ww] != -INF:
            for i in range(n + m):
                if (bit >> i) & 1:
                    continue
                nbit = bit | (1 << i)
                if i < n:
                    if ww + A[i] <= w:
                        V[nbit][ww + A[i]] = max(V[nbit][ww + A[i]], V[bit][ww] + B[i])
                else:
                    if ww - C[i - n] >= 0:
                        V[nbit][ww - C[i - n]] = max(V[nbit][ww - C[i - n]], V[bit][ww] - D[i - n])
    for ww in range(w + 1):
        ans = max(ans, V[bit][ww])
print(ans)
0