분류 전체보기
-
11726) 2×n 타일링 - Java백준코딩일기 2020. 1. 24. 13:35
https://www.acmicpc.net/problem/11726 11726번: 2×n 타일링 2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다. www.acmicpc.net 풀이) 문제에서 입력받는 N 은 1000이하의 수라고 명시하고 있으므로 배열 d 의 크기는 1000+1 을 한 만큼의 크기로 정하였다. d[n] = 2*n 크기의 직사각형을 1*2, 2*1의 타일로 채우는 방법의 수로 직접 그림을 그려 생각해보니 d[2] = 2 d[3] = 3 d[4] = 5 d[5] = 8 로 d[n] = d[n-1] + d[n-2] 라는 규칙을 찾았고, 이 규칙이 성립하기 위해 d[0] = 1로 ..