-
Notifications
You must be signed in to change notification settings - Fork 1
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
8-alstjr7437 #25
8-alstjr7437 #25
Conversation
μ λ΄λ€ λ²λ¦¬μ ¨μ£ ? |
μ λ΄λ€ λ²λ¦¬μ ¨μ£ ? |
μ§μ νμΈμ μ¬λ¬λΆ λ¬Έμ μ μ λ§ ν΄λ¬μ κ·Έλ¬μ΅λλ€.. |
2μ°¨μ DPλ μ무리 ν΄λ μ μμ΄ μλλ€μ.... μ°Ύμ보λ λͺ¨λ κ²½μ°μ μμ λν΄ κ°μ κΈ°λ‘νμ§ μκ³ , 1μ°¨μ dp 리μ€νΈλ‘ ν΄κ²°ν μ½λκ° μμ΄ κ³΅μ ν΄λ³Όκ²μ. input = open(0).readline
N, K = map(int, input().split())
objects = sorted([tuple(map(int, input().split())) for _ in range(N)])
max_values = [0] * (K + 1) # κ° λ¬΄κ² λ³ μ΅λ κ°μΉ
for weight, value in objects:
for max_load in range(K, -1, -1): # κ°λ°©μ΄ 견λ μ μλ μ΅λ 무κ²
if weight > max_load:
break
max_values[max_load] = max(max_values[max_load - weight] + value, max_values[max_load])
print(max_values[K]) μ λ ¬μ ν΄μ€ κ²½μ° κ°λ²Όμ΄ 무κ²μ 물건λΆν° κ²μ¬νκΈ° λλ¬Έμ, κ²μ¬ν μλ‘ νμΈν΄μΌ νλ λ²μκ° μ’νμ§λλ€. μ΄λ° μ μμ μλ μ μ΄λμ΄ μμ΅λλ€. |
@9kyo-hwang μ΄λΆμ΄ μ μ¨μ£Όμ ¨κ΅°μ... |
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.
μ λ λ°°λλ¬Έμ μ μ μλλ‘ ν λ² νμ΄λ΄€λλ°μ. @9kyo-hwang λμ΄λ λ°©μμ λμΌνλ°,
μ λ ¬μ μ ν΄μ€¬λ€μ. κ΅ν©λμ΄ μ μ΄μ£Όμλ κΈλ€μ λκ° κΏνμ΄ μ°Έ λ§μμ μ’μ΅λλ€!
λ¬Έμ νμ΄ μ λ΄€μ΄μ λ―Όμλ
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
items = []
dp = [0 for _ in range(K+1)]
for _ in range(N):
items.append(tuple(map(int, input().split())))
for w, v in items:
for i in range(K, w-1, -1):
dp[i] = max(dp[i], dp[i-w]+v)
print(dp[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.
λ―Όμ λ μ€λͺ λ³΄κ³ μ λ ν λ² κ΅¬νν΄ λ³΄λ μ½λκ° λκ°μ΄ λμ€λ€μ! DP λ¬Έμ ν λ μ νμμ μ°Ύλ κ² μ§μ§ μ€μν κ±° κ°μλ°, νΉμ μ νμμ μ½κ² μ°Ύλ λ Ένμ°κ° λ€λ€ μλμ?
μ μ½λμ λλ€
n,k = map(int, input().split())
weight = [0 for _ in range(n)]
value = [0 for _ in range(n)]
dp = [0 for _ in range(k+1)]
for i in range(0, n):
weight[i], value[i] = map(int, input().split())
for i in range(n):
for j in range(k,-1,-1):
if j - weight[i] >= 0 :
dp[j] = max(dp[j], dp[j-weight[i]] + value[i])
print(max(dp))
@wkdghdwns199 μ λ λ§μ΄ νμ΄λ³΄λκ² λ΅μΈ κ² κ°λ€μ.... |
π λ¬Έμ λ§ν¬
νλ²ν λ°°λ
βοΈ μμλ μκ°
2μκ°
β¨ μλ μ½λ
N - 4 / K - 7
κ΅νμΌμΈμ λμμ λ°μμ DP μ νμμ κ·Έλ Έμ΅λλ€....
μ΄λ κ² λ§λ‘ μ μΌλ μ΄ν΄κ° μκ°λ€μ μ λ...
κ°λ¨νκ² μμ λ‘ λ³΄λ©΄ μλμ κ°μ μ νμμ΄ μμ± λμ΅λλ€!
π μλ‘κ² μκ²λ λ΄μ©
dp μ νμ 그리기λ νλ€κ³ μ€λͺ νκΈ°λ μ λ§ νλλ€μ...