Skip to content

Commit

Permalink
Merge pull request #3 from AlgoLeadMe/1-pu2rile
Browse files Browse the repository at this point in the history
1-pu2rile
  • Loading branch information
pu2rile authored Apr 5, 2024
2 parents 278c474 + 742d5ab commit e7f6176
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
N, K = map(int, input().split()) #์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€๋Š” ์ˆ˜๋Š” ๋ชจ๋‘ ์ •์ˆ˜
item = [[0,0]]
bag = [[0 for _ in range(K + 1)] for _ in range(N + 1)]
#๊ฐ€๋กœ - ๊ฐ€๋ฐฉ 1~K๊นŒ์ง€์˜ ๋ฌด๊ฒŒ, ์„ธ๋กœ - ๋ฌผ๊ฑด N๊ฐœ์˜ ๊ฐœ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ 2์ฐจ์› ๋ฐฐ์—ด

for _ in range(N): #๋ฌผ๊ฑด์˜ ์ตœ๋Œ€ ๊ฐœ์ˆ˜(N)๋งŒํผ ์ž…๋ ฅ
item.append(list(map(int, input().split())))


#์•Œ๊ณ ๋ฆฌ์ฆ˜
for i in range(1, N + 1): #๋ฌผ๊ฑด
for j in range(1, K + 1): #์ตœ๋Œ€ ๋ฌด๊ฒŒ
w = item[i][0]
v = item[i][1]

if j < w:
bag[i][j] = bag[i - 1][j] #w(eight)๋ณด๋‹ค ์ž‘์œผ๋ฉด ์œ„์˜ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ด
else:
bag[i][j] = max(v + bag[i - 1][j - w], bag[i - 1][j])
#bag[i][j] = max(ํ˜„์žฌ ๋ฌผ๊ฑด ๊ฐ€์น˜ + bag[์ด์ „ ๋ฌผ๊ฑด][ํ˜„์žฌ ๊ฐ€๋ฐฉ ๋ฌด๊ฒŒ-ํ˜„์žฌ ๋ฌผ๊ฑด ๋ฌด๊ฒŒ], bag[์ด์ „ ๋ฌผ๊ฑด][ํ˜„์žฌ ๊ฐ€๋ฐฉ ๋ฌด๊ฒŒ])

print(bag[N][K])

0 comments on commit e7f6176

Please sign in to comment.