結果

問題 No.2364 Knapsack Problem
ユーザー chankei271828
提出日時 2023-07-01 00:12:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 870 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 80,312 KB
最終ジャッジ日時 2024-07-07 11:46:28
合計ジャッジ時間 2,388 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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()))
dp=[[-1]*(1<<(N+M)) for _ in range(N+M)]
w=[[-1]*(1<<(N+M)) for _ in range(N+M)]
for i in range(N+M):
    dp[i][0]=0
    w[i][0]=0
ans=0
for bit in range(1,1<<(N+M)):
    for i in range(N+M):
        if (bit>>i)&1==0:
            continue
        for j in range(N+M):
            if i<=N-1 and w[j][bit^(1<<i)]!=-1 and w[j][bit^(1<<i)]+A[i]<=W:
                dp[i][bit]=max(dp[i][bit],dp[j][bit^(1<<i)]+B[i])
                w[i][bit]=w[j][bit^(1<<i)]+A[i]
            if i>=N and w[j][bit^(1<<i)]!=-1 and w[j][bit^(1<<i)]-C[i-N]>=0:
                dp[i][bit]=max(dp[i][bit],dp[j][bit^(1<<i)]-D[i-N])
                w[i][bit]=w[j][bit^(1<<i)]-C[i-N]
        ans=max(ans,dp[i][bit])
print(ans)
#print(dp)
0