// 2×n 타일링
package Silver_III_3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ex11726 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] tile = new int[1001];
tile[1] = 1;
tile[2] = 2;
for (int i = 3; i < tile.length; i++) {
tile[i] = (tile[i-2] + tile[i-1]) % 10007;
}
System.out.println(tile[n]);
}
}
n | 1 | 2 | 3 | 4 | 5 |
방법의 수 | 1 | 2 | 3 | 5 | 8 |
tile[3] = tile[1] + tile[2] 이런식으로 n의 증가에 따라 방법의 수가 증가한다.
10007의 나머지로 계산하는 이유는 오버플로우가 안 나게 하기 위해서다.
'백준 풀이 > 자바(Java)' 카테고리의 다른 글
백준 16953 자바 - A → B (0) | 2024.05.31 |
---|---|
백준 26742 자바 - Skarpetki (0) | 2024.05.31 |
백준 25932 자바 - Find the Twins (0) | 2024.05.29 |
백준 31280 자바 - ФАКИР (0) | 2024.05.28 |
백준 26768 자바 - H4x0r (0) | 2024.05.27 |