結果
問題 | No.2364 Knapsack Problem |
ユーザー |
|
提出日時 | 2023-06-30 21:48:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,114 ms / 3,000 ms |
コード長 | 887 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 144,024 KB |
最終ジャッジ日時 | 2024-07-07 09:29:16 |
合計ジャッジ時間 | 12,651 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
import syssys.setrecursionlimit(5*10**5)input = sys.stdin.readlinefrom collections import defaultdict, deque, Counterfrom heapq import heappop, heappushfrom bisect import bisect_left, bisect_rightfrom math import gcdn,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 = [[-10**15]*(510) for i in range(1<<(n+m))]dp[0][0] = 0ans = 0for bit in range(1<<(n+m)):for i in range(n+m):if not((bit>>i)&1): continuefor w in range(510):if i < n and w >= a[i]:dp[bit][w] = max(dp[bit][w],dp[bit-(1<<i)][w-a[i]] + b[i])elif i >= n and w + c[i-n] <= W:dp[bit][w] = max(dp[bit][w],dp[bit-(1<<i)][w+c[i-n]] - d[i-n])ans = max((w <= W) * dp[bit][w], ans)print(ans)