結果

問題 No.626 Randomized 01 Knapsack
ユーザー Ryuto
提出日時 2017-12-20 00:15:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 445 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 196,352 KB
最終ジャッジ日時 2024-12-16 02:35:26
合計ジャッジ時間 16,665 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 RE * 16 TLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python

indat = [int(x) for x in input().split()]
values = list()
weights = list()
for i in range(indat[0]):
    tmp = [int(x) for x in input().split()]
    values.append(tmp[0])
    weights.append(tmp[1])

def rec(i,j):
    if i == len(weights):
        res = 0
    elif j < weights[i]:
        res = rec(i+1,j)
    else:
        res = max(rec(i+1, j), rec(i+1, j-weights[i]) + values[i])
    return res

print(rec(0, indat[1]))
0