알고리즘

[Python | 프로그래머스 | Lv_2] 2 x n 타일

deedee2 2024. 4. 5. 09:29
728x90

😄 아이디어

1. 동적프로그래밍 적용 : 피보나치

2. 모듈러 산술

def solution(n):
    answer = 0
    
    dp = [0 for _ in range(60_001)];
    idx = 0

    # DP
    # n = 1 // 1
    # n = 2 // 2
    # n = 3 // 3
    # n = 4 // 5
    while (n >= idx):
        idx += 1
        if idx == 1:
            dp[idx] = 1
            continue
        elif idx == 2:
            dp[idx] = 2
            continue
        
        dp[idx] = (dp[idx - 2] + dp[idx - 1]) % 1_000_000_007            
    return dp[idx - 1]

✔️링크:https://school.programmers.co.kr/learn/courses/30/lessons/12900#