Files
baekjoon-study/workbook_7319/silver/11727-s3.py
2026-03-27 09:23:14 +09:00

32 lines
960 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 2×n 타일링 2
import sys
input = sys.stdin.readline
def solution():
n = int(input().rstrip())
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1
for i in range(2, n+1):
dp[i] = (dp[i-1]*1) + (dp[i-2]*2)
print(dp[n]%10007)
return
solution()
"""
걸린 시간: 10분
시간 복잡도: n짜리 테이블을 한번씩만 보면서 채우기 때문에 O(n)이다.
해설: 과거부터 쌓아온 경우의 수가 현재의 결과에 영향을 미치고, 한 번 결정되면 바뀌지 않기 때문에 dp이다.
현재 1칸이 생겼을 때 과거로부터 놓는 경우를 생각해보면 꽉채워진 상태에서 2x1을 놓는 방법 1가지와 한칸 남겨놓고 2x2에서 만들 수 있는 경우의 수 2가지이다.
이전까지의 경우의 수에 다음 놓을 수 있는 경우의 수가 1가지라면 dp[i-1]*1이고, 2가지일때는 dp[i-2]*2이다.
이 둘을 합친 것이 현재 칸의 경우의 수이다.
"""