結果

問題 No.2364 Knapsack Problem
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-06-30 22:07:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 3,000 ms
コード長 671 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 76,788 KB
最終ジャッジ日時 2023-09-21 16:09:11
合計ジャッジ時間 3,275 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,060 KB
testcase_01 AC 73 ms
71,392 KB
testcase_02 AC 75 ms
71,052 KB
testcase_03 AC 73 ms
71,108 KB
testcase_04 AC 74 ms
71,352 KB
testcase_05 AC 76 ms
71,268 KB
testcase_06 AC 74 ms
71,392 KB
testcase_07 AC 101 ms
76,508 KB
testcase_08 AC 79 ms
71,592 KB
testcase_09 AC 92 ms
76,452 KB
testcase_10 AC 94 ms
76,612 KB
testcase_11 AC 75 ms
71,388 KB
testcase_12 AC 95 ms
76,788 KB
testcase_13 AC 94 ms
76,668 KB
testcase_14 AC 95 ms
76,632 KB
testcase_15 AC 97 ms
76,452 KB
testcase_16 AC 98 ms
76,528 KB
testcase_17 AC 97 ms
76,504 KB
testcase_18 AC 99 ms
76,392 KB
testcase_19 AC 98 ms
76,560 KB
testcase_20 AC 96 ms
76,504 KB
testcase_21 AC 96 ms
76,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,w = map(int,input().split())
WV = []
for i in range(2):
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    for a,b in zip(A,B):
        if i == 0:
            WV.append([a,b])
        else:
            WV.append([-a,-b])


inf = 10**10
l = n+m
dp = [-inf]*(1<<l)
dp[0] = 0
ans = 0
for b in range(1<<l):
    if dp[b] == -inf:
        continue
    ans = max(ans,dp[b])
    size = 0
    for i in range(l):
        if b >> i & 1:
            size += WV[i][0]
    
    for i in range(l):
        if b >> i & 1:
            continue

        x,y = WV[i]
        if 0 <= size+x <= w:
            dp[b|1<<i] = max(dp[b|1<<i],dp[b]+y)
print(ans)
0