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

[weekly] 이아영 / 0924 계단오르기 #34

Merged
merged 1 commit into from
Sep 25, 2024
Merged

[weekly] 이아영 / 0924 계단오르기 #34

merged 1 commit into from
Sep 25, 2024

Conversation

aaaange
Copy link
Collaborator

@aaaange aaaange commented Sep 24, 2024

후기

  • 본인이 생각한 이 문제의 알고리즘
    dp

  • 본인이 생각한 이 문제의 주요 아이디어

  • 문제를 풀다가 한 실수
    규칙성을 찾는 게 어려워서 여러가지 시도해보다가 서칭 엔딩.. 총총

  • 문제를 풀면서 새롭게 배운 점

@aaaange aaaange self-assigned this Sep 24, 2024
@kminsong kminsong merged commit 1d885ca into main Sep 25, 2024
Copy link
Owner

@minjeeki minjeeki left a comment

Choose a reason for hiding this comment

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

아영이 코드를 돌려줘 깃허브야!

@minjeeki
Copy link
Owner

아영이 코드 (mm에서 복사)

n = int(input()) # 계단 개수
s = [int(input()) for _ in range(n)] # 계단 리스트

dp = [0]*(n) # dp 리스트 : 각 인덱스에 최대 점수가 들어감

if len(s) <= 2: # 계단이 2개 이하일땐 그냥 다 더해서 출력
    print(sum(s))

else: # 계단이 3개 이상일 때
    dp[0] = s[0] # 첫째 계단 수동 계산
    dp[1] = s[0] + s[1] # 둘째 계단까지 수동 계산

    for i in range(2,n): # 3번째 계단 부터 dp 점화식 이용해서 최대값 구하기
        dp[i] = max( dp[i-3] + s[i-1] + s[i], dp[i-2] + s[i] )
        # 현재 계단으로 오는 길은 2가지 
        # (전전칸 스킵)전칸을 밟고 오느냐, 전칸을 스킵하고 오느냐
    print(dp[-1])

@minjeeki
Copy link
Owner

dp[i] = max( dp[i-3] + s[i-1] + s[i], dp[i-2] + s[i] )

아영이 점화식 보니까 이해 잘된다!

현 위치로 오는 방법은
(1) 2칸 전꺼를 밟고 바로 오는 경우
(2) 1칸 전꺼를 밟고 오는 경우 + 근데 1칸 전꺼를 밟고 오기 위해서는 전전 단계에서 2칸 전꺼를 밟고 와야 함
이거 맞지?? 근데 한번 그림 그려봐야 이해할 수 있을 것 같아! ㅋㅋㅋㅋ 그래도 고마웡!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants