Skip to content
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

9-seongwon #38

Merged
merged 1 commit into from
May 13, 2024
Merged

9-seongwon #38

merged 1 commit into from
May 13, 2024

Conversation

seongwon030
Copy link
Collaborator

πŸ”— 문제 링크

1,2,3 λ”ν•˜κΈ° 3

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1μ‹œκ°„

✨ μˆ˜λ„ μ½”λ“œ

λ¨Όμ € 점화식을 μ„Έμ› λ‹€. λ””ν”ΌλŠ” μ†μˆ˜ μ μ–΄μ„œ μ–΄λ–€ 경우의 μˆ˜κ°€ λ‚˜μ˜€λŠ”μ§€ 확인해야 μ–΄λ–»κ²Œ ν‘ΈλŠ”μ§€ λˆˆμ— λ³΄μ΄λŠ” 것 κ°™λ‹€.
λ¨Όμ € n=1 λΆ€ν„° λͺ‡ 가지 경우의 μˆ˜κ°€ λ‚˜μ˜€λŠ”μ§€ μ²΄ν¬ν–ˆλ‹€. 문제의 μ˜ˆμ—μ„  μˆœμ„œκΉŒμ§€ κ³ λ €ν•œλ‹€.

n=1 일 λ•Œ

(1)

n=2 일 λ•Œ

(1,1), (2)

n=3 일 λ•Œ

(1,1,1), (1,2), (2,1), (3)

n=4 일 λ•Œ

(1,1,1,1), (1,1,2), (1,2,1), (2,1,1), (2,2), (1,3), (3,1)

정리

n 경우의수
1 1
2 2
3 4
4 7

μ—¬κΈ°μ„œ dp[n] = dp[n-3]+dp[n-2]+dp[n-1]의 점화식을 얻을 수 μžˆλ‹€.

μ½”λ“œ

import sys

input = sys.stdin.readline
dp = [1,2,4,7]
p = 4
for i in range(int(input())):
  n = int(input())
  while(n>p):
    dp.append((dp[p-3]+dp[p-2]+dp[p-1])%1000000009)
    p+=1
  print(dp[n-1])

dp에 n=1 λΆ€ν„° 4κΉŒμ§€μ˜ 경우의 수λ₯Ό μ €μž₯ν•˜μ—¬ pλ₯Ό 4λΆ€ν„° κ³„μ‚°ν•˜λ„λ‘ ν–ˆλ‹€. n이 p보닀 μž‘μ•„μ§€κΈ° μ „κΉŒμ§€ κ³„μ‚°ν•˜μ—¬ n에 ν•΄λ‹Ήν•˜λŠ” 인덱슀인 n-1번째 dpλ₯Ό 좜λ ₯ν•œλ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

dpλŠ” 점화식뢀터 κ΅¬ν•˜μž.

Copy link
Collaborator

@yuyu0830 yuyu0830 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ˜ˆμ‹œλ₯Ό ꡬ해본 λ’€ 점화식을 κ΅¬ν•˜κ³ , 점화식에 λ§žκ²Œλ” 문제λ₯Ό ν•΄κ²°ν•˜κΈ° κΉŒμ§€ ꡉμž₯히 μˆ˜μ›”ν•œ νλ¦„μ΄μ˜€λ„€μš”!사싀 이런 λ¬Έμ œλŠ” 점화식을 κ΅¬ν•˜λ©΄ 금방 ν’€λ¦¬λŠ”λ° κΉ”λ”ν•œ 점화식이 μ•ˆλ‚˜μ˜€λ©΄ 풀이가 κΈΈμ–΄μ§€λŠ” κ²½μš°κ°€ 있죠.. 쉽고 κ°„λ‹¨ν•œ μ„€λͺ…κΉŒμ§€ 잘 보고 κ°‘λ‹ˆλ‹€.

Copy link
Collaborator

@InSange InSange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dp둜 ν’€μ—ˆλ‹€λ‹ˆ.. 상상도 λͺ»ν–ˆμ‹¬λ‹ˆλ‹€..
μ•ˆμ— κ·œμΉ™μ΄ μˆ¨μ–΄ μžˆμ—ˆκ΅°μš”?
μƒμ›ν–‰λ‹˜μ΄ λ§μ”€ν•˜μ‹  κ²ƒμ²˜λŸΌ dpμ—μ„œ μ–΄λ–€ μˆ˜μ‹μ„ 찾을 λ•Œ 길이λ₯Ό 찾지 λͺ»ν•˜λ©΄ κΈΈμ–΄μ§ˆλ•Œ κΉŒμ§€ ν•˜κ²Œλ˜μ–΄μ„œ λͺ¨λ“  경우의 수λ₯Ό μ°ΎκΈ°κ°€ νž˜λ“­λ‹ˆλ‹€.

μ € 같은 κ²½μš°λŠ” 3을 0λΆ€ν„° μ¦κ°€μ‹œμΌœμ„œ n λ‚˜λˆ„κΈ° 2의 λͺ«μœΌλ‘œ 개수λ₯Ό μΉ΄μš΄νŒ…ν•˜λŠ” 방식을 μƒκ°ν–ˆλŠ”λ° μ΄λ ‡κ²Œ 되면 ν…ŒμŠ€νŠΈμΌ€μ΄μŠ€μ— 따라 λ‹€μ‹œ κ΅¬ν•΄μ•Όλ˜μ–΄μ„œ μ–΄λ–»κ²Œ μ‹œκ°„ λ³΅μž‘λ„λ₯Ό μ€„μ΄λ‚˜ κ³ λ―Όν–ˆμ—ˆμŠ΅λ‹ˆλ‹€.

κ·Έλž˜λ„ dpκΉŒμ§„ 닿지 λͺ»ν–ˆλŠ”데 이게 싀버 λ¬Έμ œμ˜€λ‹€λ‹ˆ...
풀이 잘 보고 κ°‘λ‹ˆλ‹€ :)

Copy link
Contributor

@dhlee777 dhlee777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ¨Όμ € 경우의수λ₯Ό μ •λ¦¬ν•œλ’€ 점화식을 μ„Έμš°λ‹ˆ κΉ”λ”ν•˜κ²Œ 잘 λ§Œλ“€μ–΄μ§€λŠ” κ±° κ°™μ•„μš”. μ΄λ•ŒκΉŒμ§€ dp문제λ₯Ό ν’€λ•Œ μ§κ΄€μ μœΌλ‘œ 푼감이 μ—†μ§€μ•Šμ•„ μžˆμ—ˆλŠ”λ° μ΄λ ‡κ²Œ ν•˜λ‚˜ν•˜λ‚˜ 경우의수λ₯Ό 적어가며 ν’€μ–΄λ΄μ•Όκ² μŠ΅λ‹ˆλ‹€

@seongwon030 seongwon030 merged commit de75008 into main May 13, 2024
1 check passed
@seongwon030 seongwon030 deleted the 9-seongwon branch May 13, 2024 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants