Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π λ¬Έμ λ§ν¬
1λ‘λ§λ€κΈ°
βοΈ μμλ μκ°
1μκ° 30λΆ
β¨ μλ μ½λ
μ΄λ€μλ₯Ό 1λ‘λ§λλλ° κ±Έλ¦¬λ μ΅μ μ°μ°νμλ₯Ό ꡬνλ λ¬Έμ λ‘
dp
λ₯Ό μ΄μ©ν΄μ νμ΄λ³΄μλ€.μ°μ°μ μ’ λ₯λ μ΄ 3κ°μ§λ‘
1. 1μλΊλ€
2. 3μΌλ‘λλμ΄λ¨μ΄μ§λ©΄ 3μΌλ‘ λλλ€.
3. 2λ‘λλμ΄ λ¨μ΄μ§λ©΄ 2λ‘ λλλ€.
μ°μ νΉμ μ i(1<=i<=10^6) μμμ 1λ‘λ§λλλ° νμν μ°μ°νμλ₯Ό μ μ₯νλ
λ°°μ΄ dp[i]
λ₯Ό μ μΈν΄μ€λ€.κ·Έλ¦¬κ³ iκ° 1μΌλ μ°μ°νμλ 0 , 2μΌλλ 1, 3μΌλλ 1μ΄λ―λ‘ μ΄κΈ°κ° μ€μ μ ν΄μ€λ€.(
dp[1]=0;dp[2]=1,dp[3]=1
)κ·Έλ¦¬κ³ 1λ² μ°μ°
dp[i]=dp[i-1]+1
μκΈ°λ³Έ
μΌλ‘ μ€μ ν λ€μ iκ° 3μΌλ‘ λλμ΄λ¨μ΄μ§λ€λ©΄dp[i] = min(dp[i], dp[i / 3] + 1)
λ₯Όν΅ν΄ κΈ°λ³Έκ°κ³Όμ λμλΉκ΅, iκ° 2λ‘ λλμ΄λ¨μ΄μ§λ€λ©΄
dp[i] = min(dp[i], dp[i / 2] + 1)
λ₯Ό ν΅ν΄μ΅μκ°
μ μ°Ύμμ€λ€.π μλ‘κ² μκ²λ λ΄μ©
dp
λ₯Ό μ€λλ§μ νμ΄λ΄€λλ° μ νμμ μκ°ν΄λ΄κΈ°μ μ¬μ ν λ§μμκ°μ΄ 걸리λ κ² κ°λ€.