2021.04.18

2×n 타일링

2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오.


/**
* n = 1     1    |
*     2     2    || , =
*     3     3    |||, =|, |= 
*     4     5    ||||, ==, |=|, ||=, ==| 
*     5     8    |||||, |==, =|=, ==|, ||=|, |||=, =|||, |=|||
*
* d[n] = d[n-2] + d[n-1]
*/

n = int(input())

d = [1, 2]

for i in range(2, n):
  d.append(d[i-2] + d[i-1])

print(d[n-1] % 10007)



Discussion and feedback