結果
| 問題 |
No.626 Randomized 01 Knapsack
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-30 01:13:49 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 807 bytes |
| コンパイル時間 | 211 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 13,684 KB |
| 最終ジャッジ日時 | 2024-11-22 11:09:08 |
| 合計ジャッジ時間 | 3,036 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
import sys
sys.setrecursionlimit(10 ** 7)
n, cap = map(int, input().split())
best = 0
goods = [list(map(int, input().split())) for i in range(n)]
goods.sort(key=lambda x: x[0] / x[1], reverse=True)
v_cum = [0]
def dfs(ind, v, w):
global best
if w > cap: return
if ind == n: best = max(best, v); return
v_l = v
w_new = cap - w
cur = ind
while cur < n and 0 <= w_new - goods[cur][1]:
w_new -= goods[cur][1]
v_l += goods[cur][0]
cur += 1
cur -= 1
if cur == n and w_new == 0: bese = max(best, v_l); return
opt = v_l + goods[cur][0] * (w_new / goods[cur][1])
if opt <= best: return
dfs(ind + 1, v + goods[ind][0], w + goods[ind][1])
dfs(ind + 1, v, w)
for i in range(n): v_cum.append(v_cum[-1] + goods[i][0])
dfs(0, 0, 0)
print(best)