-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2-kokeunho #5
2-kokeunho #5
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ λ λ‘μ§μ λΉμ·νκ² κ΅¬ννμ΅λλ€. cppλ‘ νλ 0-based λ°°μ΄μ΄λ 1-basedλ°°μ΄ λλ¬Έμ μ‘°κΈ ν·κ°λ¦¬λ€μ. μ 체 μ½λ
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <details> ``` μμ κ°μ΄ μμ±νμλ©΄ μ 체 μ½λλ₯Ό ν κΈλ‘ λ£μ μ μμ΅λλ€!! μ°Έκ³ νμΈμ© There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ€ λ§ν¬μ κΏν κ°μ¬ν©λλ€ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
N, K = map(int, input().split()) | ||
items = [] | ||
|
||
for _ in range(N): | ||
W, V = map(int, input().split()) | ||
items.append((W, V)) | ||
|
||
dp = [[0] * (K+1) for _ in range(N+1)] | ||
|
||
for i in range(1, N+1): | ||
weight, value = items[i-1] | ||
for j in range(1, K+1): | ||
if j >= weight: | ||
dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight] + value) | ||
else: | ||
dp[i][j] = dp[i-1][j] | ||
|
||
print(dp[N][K]) | ||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λμ κ³νλ²μ λ°°μ°κΈ° μ’μ μμ κ°μ΅λλ€. μμ μκ³ λ¦¬μ¦ κ°μ λ bruteforceλ‘λ νμ΄λ΄€κ³ dpλ‘λ νμ΄λ΄€λ κΈ°μ΅μ΄ λλ€μ.
μμ μ λ°±μ€μμλ κ°μ λ¬Έμ λ₯Ό νμ΄λ΄€μμ΅λλ€. μ½λ μΌλΆλ₯Ό 보λ c++λ‘ νμ΄ν μ μ½λλ κ±°μ μ μ¬νλ€μ.