BOJ(2Xn타일링)(1,2)

2Xn 타일링

n = int(input())
a, b = 1, 2
for i in range(2, n+1):
    a, b = b % 10007, a+b % 10007
print(a)
n = int(input())
d = [1, 1] + [0]*1000
a, b = 1, 2
for i in range(2, n+1):
    d[i] = d[i-1] + d[i-2]
    d[i] %= 10007
print(d[n])

2Xn 타일링 2

n = int(input())
d = [1, 1] + [0]*n
for i in range(2, n+1):
    d[i] = d[i-1] + d[i-2]*2
    d[i] %= 10007
print(d[n])
n = int(input())
a, b = 1, 3
for i in range(2, n+1):
    if i % 2 == 0:  # 짝수면
        a = (b*2-1) % 10007
    else:
        b = (a*2+1) % 10007
print(a if n % 2 == 1 else b)

참고자료 codeplus

0%