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.
π λ¬Έμ λ§ν¬
BOJ 11726 - 2Γn νμΌλ§
βοΈ μμλ μκ°
λλ΅ 15~20λΆ?
β¨ μλ μ½λ
1. λ¬Έμ μ€λͺ
2Γnμ νμΌμ 2Γ1μ μ§μ¬κ°νμΌλ‘ μ±μΈ μ μλ λ°©λ²μ κ²½μ°μ μ % 10007μ μΆλ ₯νλ λ¬Έμ μ΄λ€.
2. λ¬Έμ ν΄μ
1. μΌμΌν λΆμ
λͺ νν νμ΄λ²μ λͺ» μ°Ύκ² μΌλ μΌλ¨ κ²½μ°μ μλ₯Ό λμ΄νλ©΄μ λ΅μ ꡬν΄λ΄ μλ€.
μ νμ 보μ΄μλμ? ν보λμΉ μμ΄μ΄λ λΉμ·νμ£ ?
κ°λ¨ν μ νμ μ½λμ λλ€.
2. DP
μ μ½λλ μμΉ«νλ©΄ μκ° μ΄κ³Όκ° λ κ°λ₯μ±μ΄ μ‘΄μ¬ν©λλ€.
n
μ΄ 1000λ³΄λ€ μμ μμ°μμ΄κΈ°μ μκ° μ‘°κΈλ§ μ»€μ Έλ μκ°μ΄ λ§μ΄ 걸립λλ€.μ΄λ
DP
λ₯Ό μ¬μ©ν΄μ£Όμ΄μΌ ν©λλ€. μ½κ² λ§ν΄μ λ΅μ μ¬μ¬μ©ν μ μκ² κ°n
μ λ°λ₯Έf(n)
μ μ μ₯νμ¬ κΊΌλ΄ μ°λκ²λλ€.DP[n-1]
μλfunc(n)
μ κ°μ΄ λ€μ΄μμ΅λλ€. μ΄κΉκ°μDP[0]
κ³ΌDP[1]
μ μ μΈνκ³ μ λΆ 0μ λλ€.DP[0]
κ³ΌDP[1]
μλ κ°κ°1
κ³Ό2
μ κ°μ΄ λ€μ΄κ°μΌ ν©λλ€. λμf(n) = n
μ΄λΌλ μμΈμ κ°μ κ°μ§κΈ° λλ¬Έμ λλ€.κ·ΈλΌ μ΄μ μκ°μ ν΄λ΄ μλ€.
λ§μ½
func
ν¨μλ₯Ό νΈμΆνμ λDP
κ° λ§μ½ 0μ΄λ©΄ μ§μ DP
μ κ°μ μ μ₯ν©λλ€. κ·Έ νreturn
νλ©΄ λκ² μ£ ?DP
κ° λ§μ½ 0μ΄ μλλ©΄ κ·Έ κ°μ΄ μ μ₯λμ΄ μλ€λ λ»μ΄λ κ·Έλ₯return
νλ©΄ λ κ²λλ€.3. mod 10007
10007λ‘ λλμμ λ λλ¨Έμ§μ κ°μ μΆλ ₯ν΄μΌ νλ―λ‘ λλ¨Έμ§ μ°μ°λ μΆκ°ν΄μ£Όμ΄μΌ ν©λλ€.
κΈ°μ‘΄μ μ νμμμ mod μ°μ°μ μΆκ°ν μ½λλ‘ λ°κΎΈμ΄ μ μ©ν΄μ£Όμ΄μΌ ν©λλ€.
3. μλ μ½λ
4. μ΅μ’ μ½λ
π μλ‘κ² μκ²λ λ΄μ©
DP μ°μ΅νκΈ°
μμ¦ λ무 λ°λΉ μ μκ³ λ¦¬μ¦μ μκ° λͺ» μλκ² μ’ μμ½λ€μ.
νλ°μ΄ λ¬Έμ μΆμ²: 2Γn νμΌλ§ 2
μ¬μ§ νΌμ¨ λΈλ‘κ·Έ: λ§ν¬