N을 2a + 1b꼴로 만들어서 조합을 사용해서 수를 구하면 된다고 생각했는데 시간초과가 나왔다.. 겹치는 친구들이 있어서 점화식을 불가능하다고 생각했는데 검색해보니까 점화식이 되더라..? 왜 되는지 고민해 보았다.
import sys
from math import factorial
input = sys.stdin.readline
N = int(input())
def combi(n, r):
return factorial(n) // (factorial(r)*factorial(n-r))
def tile(n):
count = 0
for a in range(n//2 + 1): # 2*a + 1*b꼴, a는 0~n//2까지 가능
b = n - 2*a
count += combi(a+b, a)
return count
print(tile(N) % 15746)
import sys
from math import factorial
input = sys.stdin.readline
N = int(input())
tile = [0, 1, 2]
for i in range(3, N+1):
tile.append((tile[i-2] + tile[i-1]) % 15746)
print(tile[N])
