728x90
😉 아이디어
1. _!n!_이 홀수일 때는 생성불가 _!return 0!_ 짝수만 고려
2. _!n = 2인 경우 신규 패턴 3개 생성!_, _!n = 4인 경우 이후 2개씩 생성!_
3. _!f(10) = f(8) * 3 + f(6) * 2 + f(4) + f(2) * 2 + 2!_
😉 풀이
def solution(n):
answer = 0
if n == 1 :
return 0
MOD = 1_000_000_007
arr = [0] * (n + 10)
arr[2] = 3
arr[4] = 11
for i in range(6, n + 10):
if i % 2 == 1:
continue
arr[i] = (arr[i - 2] * 3 + sum(arr[:i - 2]) * 2 + 2) % MOD
return arr[n]
✔ 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/12902