-
Notifications
You must be signed in to change notification settings - Fork 5
6-wonjunYou #146
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
6-wonjunYou #146
Conversation
μ΅μ Cλͺ κ³Ό μ μλ°° ν¬μκ° κ°λ₯νλ€λ μ§λ¬Έμ μ°Ύμμ λ¬Έμ λ₯Ό νΈμ κ² μ λ§ λλ¨ν©λλ€ .. ! μ λ μμ§ λ¬Έμ κ° μ΄λ ΅λ€μ T.T μ νμ λΆλΆμ΄ μ΄ν΄κ° μ μλμ΄μ μμλ₯Ό μ°Ύμκ°λ©΄μ μ§μ νλ² κ³ λ―Όν΄λ³Ό μ μμλ μ’μ λ¬Έμ μμ΅λλ€ ! C = 12 (λͺ©ν κ³ κ° μ)
μ΄λ κ² κ° λμμ λΉμ©κ³Ό κ³ κ° μλ₯Ό λΉκ΅νλ©° Cλͺ
μ΄μμ λͺ¨λ κ²½μ° μ€μμ μ΅μ λΉμ©μ μ°Ύκ³ |
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.
μμΈν μ€λͺ λλΆμ μ νμμ ꡬνλ κ³Όμ μ μ΄ν΄ν μ μμμ΅λλ€!
κ·Έλ¦¬κ³ Integer.MAX_VALUE + cost
λ₯Ό ν΄λ²λ¦¬λ©΄ int λ²μλ₯Ό λ²μ΄λκΈ° λλ¬Έμ μμκ° λμ΄μ minκ°μΌλ‘ μΈμλκΈ° λλ¬Έμ if (dp[j - customer] != Integer.MAX_VALUE)
쑰건μ μΆκ°νμ λΆλΆμ μ²μμ κ³ λ €λ₯Ό λͺ»νλλ°,
λ€λ₯Έ λ¬Έμ λ₯Ό νμ΄ν λλ μ΄λ° λΆλΆλ€μ λλ²μΈλ² 체ν¬νλ©΄μ μ½λλ₯Ό μμ±ν΄μΌκ² λ€λ μκ°μ νμ΅λλ€ π₯Ή
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λ‘ μ κ·Όνμλλ° λ§νλ λΆλΆλ€μ΄ μμ΄μ μμ€λμ μλμ½λλ₯Ό 보λ μ£Όμν΄μΌ ν 쑰건λ€μ΄ μμκ΅°μ!
λλΆμ ν΄κ²° 쑰건λ€μ κ³ λ €νμ¬ μ½λλ₯Ό ꡬνν΄λ³Ό μ μμμ΅λλ€π
required_customers, num_cities = map(int, input().split())
city_costs = []
for _ in range(num_cities):
cost, customers = map(int, input().split())
city_costs.append((cost, customers))
max_customers = required_customers + 100
min_cost_to_achieve = [float('inf')] * max_customers
min_cost_to_achieve[0] = 0
for cost, customers in city_costs:
for target in range(customers, max_customers):
min_cost_to_achieve[target] = min(min_cost_to_achieve[target], min_cost_to_achieve[target - customers] + cost)
print(min(min_cost_to_achieve[required_customers:]))
μ΄λ² PRλ μκ³ νμ ¨μ΅λλ€π
π λ¬Έμ λ§ν¬
νΈν
λ¬Έμ μ€λͺ
νΈν μ μ¬μ₯μΈ κΉννμ μ΄λ²μ μμ μ μ‘°κΈ λ리기 μν΄μ ν보λ₯Ό νλ €κ³ νλ€.
ννμ΄κ° ν보λ₯Ό ν μ μλ λμκ° μ£Όμ΄μ§κ³ , κ° λμλ³λ‘ ν보νλλ° λλ λΉμ©κ³Ό, κ·Έ λ λͺ λͺ μ νΈν κ³ κ°μ΄ λμ΄λλμ§μ λν μ λ³΄κ° μλ€.
μ΄λ μ 보λ, βμ΄λ€ λμμμ 9μμ λ€μ¬μ ν보νλ©΄ 3λͺ μ κ³ κ°μ΄ λμ΄λλ€.βμ κ°μ μ 보μ΄λ€.
μ΄λ¬ν μ 보μ λνλΈ λμ μ μλ°°(nλ°°) λ§νΌμ ν¬μν μ μλ€. (ex. 18μμ λ€μ¬μ 6λͺ μ κ³ κ°)
λ¨, μ μλ°°κ° μλ κ²½μ° 3μμ λ€μ¬μ ν보ν΄μ 1λͺ μ κ³ κ°, 12μμ λ€μ¬μ 4λͺ μ κ³ κ°μ λμ΄λκ² ν μλ μλ€.
μ΄λ, νΈν μ κ³ κ°μ μ μ΄λ Cλͺ λμ΄κΈ° μν΄ ννμ΄κ° ν¬μν΄μΌ νλ λμ μ΅μκ°μ ꡬνλΌ.
첫째 μ€μ Cμ ννμ΄κ° ν보ν μ μλ λμμ κ°μ Nμ΄ μ£Όμ΄μ§λ€. Cλ 1,000λ³΄λ€ μκ±°λ κ°μ μμ°μμ΄κ³ , Nμ 20λ³΄λ€ μκ±°λ κ°μ μμ°μμ΄λ€. λμ§Έ μ€λΆν° Nκ°μ μ€μλ κ° λμμμ ν보ν λ λλ λΉμ©κ³Ό κ·Έ λΉμ©μΌλ‘ μ»μ μ μλ κ³ κ°μ μκ° μ£Όμ΄μ§λ€. μ΄ κ°μ 100λ³΄λ€ μκ±°λ κ°μ μμ°μμ΄λ€.
βοΈ μμλ μκ°
40λΆ
β¨ μλ μ½λ
μ°μ ν΄λΉ λ¬Έμ λ μ νμ μΈ DPμ²λΌ 보μ΄μ§λ§, μλ 쑰건μ μ£Όμν΄μΌ ν©λλ€.
οΏ½μ¦ dp ν μ΄λΈμμ κ³ κ°μ μκ° λ λ§μ§λ§, λ°λλ‘ λΉμ©μ΄ λ μ μ κ²½μ°κ° μ‘΄μ¬ν μ μμ΅λλ€.
λ¬Έμ 쑰건μμ ν λ²μ νλ³΄λ‘ μ΅λ 100λͺ μ κ³ κ°μ λͺ¨μ μ μμΌλ―λ‘, dp ν μ΄λΈμ μ΅λ λ²μλ₯Ό
c + 100
μΌλ‘ μ€μ νμ΅λλ€.μ΅μ λΉμ©μ ꡬν΄μΌ νλ―λ‘, μ μ μ΅λκ°μΌλ‘ μ΄κΈ°ννμμ΅λλ€.
μ΄μ΄ DP μ νμμ λ€μκ³Ό κ°μ΄ ꡬνμ΅λλ€.
νμ§λ§, μ΄λ¬ν κ²½μ°
dp[j - customer]
κ°Integer.MAX_VALUE
μ¬μ μμ κ°μ΄ λμ΄ ν΄λΉ μ νμμ΄ λ¬΄ν 루νκ° μκΈΈ μ μμ΅λλ€.λ°λΌμ, ν΄λΉ 쑰건μ λν μ²λ¦¬λ₯Ό μΆκ°νμ¬ ν΄κ²°ν μ μμμ΅λλ€ !!
μ 체 μ½λ