結果

問題 No.626 Randomized 01 Knapsack
ユーザー wajima_wataruwajima_wataru
提出日時 2017-12-30 16:50:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 530 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 8,132 KB
最終ジャッジ日時 2023-08-23 11:04:13
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,896 KB
testcase_01 AC 17 ms
7,792 KB
testcase_02 AC 60 ms
7,776 KB
testcase_03 AC 57 ms
8,132 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, W = map(int, input().split()) 
VW = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[0]/x[1], reverse=True)
SUM_V = [0 for _ in range(N)]
cur_sum = 0
for i in range(N - 1, -1, -1):
	cur_sum += VW[i][0]
	SUM_V[i] = cur_sum
ans = 0

def culc(cur_i, cur_v, cur_w):
	global ans
	ans = max(ans, cur_v)
	if cur_i == N or cur_v + SUM_V[cur_i] < ans:
		return
	if cur_w + VW[cur_i][1] <= W:
		culc(cur_i + 1, cur_v + VW[cur_i][0], cur_w + VW[cur_i][1])
	culc(cur_i + 1, cur_v, cur_w)
culc(0, 0, 0)
print(ans)
0