Submission #2897812
Source Code Expand
def d_simple_knapsack(N, W, Baggage): from collections import defaultdict # dp[w]:ナップサックに重さがwになるように荷物を入れたときの価値の最大値 dp = defaultdict(int) dp[0] = 0 # 重さ0で達成できる価値は0とする for w, v in Baggage: # dpの各要素(現時点におけるナップサック内の荷物の重さ)に対して、 # 注目した荷物を入れても重さがWを超えなければ、 # ナップサックに荷物を入れて価値の最大値を更新する latest_dp = list(dp.items()) for kw, kv in latest_dp: if kw + w <= W: dp[kw + w] = max(dp[kw + w], kv + v) ans = max(dp.values()) return ans N, W = [int(i) for i in input().split()] Baggage = [[int(i) for i in input().split()] for j in range(N)] print(d_simple_knapsack(N, W, Baggage))
Submission Info
Submission Time | |
---|---|
Task | D - Simple Knapsack |
User | kenseiQ |
Language | Python (3.4.3) |
Score | 400 |
Code Size | 917 Byte |
Status | AC |
Exec Time | 67 ms |
Memory | 4012 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2, example3 |
All | antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
antigreedy0 | AC | 23 ms | 3316 KB |
antigreedy1 | AC | 24 ms | 3316 KB |
antigreedy2 | AC | 23 ms | 3316 KB |
example0 | AC | 21 ms | 3316 KB |
example1 | AC | 21 ms | 3316 KB |
example2 | AC | 21 ms | 3316 KB |
example3 | AC | 21 ms | 3316 KB |
quarter0 | AC | 67 ms | 4012 KB |
quarter1 | AC | 54 ms | 3872 KB |
quarter2 | AC | 32 ms | 3500 KB |
rand0 | AC | 21 ms | 3316 KB |
rand1 | AC | 21 ms | 3316 KB |
rand2 | AC | 21 ms | 3316 KB |
smallw0 | AC | 21 ms | 3316 KB |
smallw1 | AC | 21 ms | 3316 KB |
smallw2 | AC | 25 ms | 3372 KB |