-
11726) 2×n 타일링 - Java백준코딩일기 2020. 1. 24. 13:35
https://www.acmicpc.net/problem/11726
풀이)
문제에서 입력받는 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로 d[1] = 1 로 미리 정의해주었다.
123456789101112131415161718192021public class Main {public static void main(String[] args) throws IOException{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));int n = Integer.parseInt(br.readLine());int[] d = new int[1001];d[0] = 1;d[1] = 1;for(int i=2; i<=n; i++) {d[i] = d[i-1] + d[i-2];d[i] %= 10007;}}} cs'백준코딩일기' 카테고리의 다른 글
2960) 에라토스테네스의 체 - Java (0) 2020.01.29 11727) 2×n 타일링 2 - Java (0) 2020.01.24 2004) 조합 0의 개수 - Java (0) 2020.01.15 10872) 팩토리얼 - JAVA (0) 2020.01.15 1676) 팩토리얼 0의 개수 - JAVA (0) 2020.01.15