結果

問題 No.527 ナップサック容量問題
ユーザー neterukunneterukun
提出日時 2019-06-10 05:51:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 99,968 KB
最終ジャッジ日時 2024-04-15 20:13:33
合計ジャッジ時間 4,922 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 44 ms
52,480 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 79 ms
68,224 KB
testcase_06 AC 154 ms
92,928 KB
testcase_07 WA -
testcase_08 AC 73 ms
66,048 KB
testcase_09 AC 43 ms
52,096 KB
testcase_10 WA -
testcase_11 AC 97 ms
73,728 KB
testcase_12 AC 80 ms
68,864 KB
testcase_13 AC 159 ms
94,976 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 44 ms
51,968 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
v = int(input())

sum_w = 0
for i in range(n):
    sum_w += info[i][1]

# dp[i][j] := i番目の荷物を入れたときの、重さj以下で実現できる最大価値
dp = [[0]*(sum_w+1) for i in range(n+1)]

for i in range(n):
    for j in range(sum_w+1):
        if j - info[i][1] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-info[i][1]] + info[i][0])

flag = False
min_w = 1
max_w = "inf"
for i in range(1, sum_w+1):
    if dp[n][i] == v:
        min_w = j
        break

for j in range(i+1, sum_w+1):
    if dp[n][j] != v:
        max_w = i - 1
        break

print(min_w)
print(max_w)
0