알고리즘 풀이/백준(BOJ)
[JAVA/백준11726] 2xn 타일링 DP
닥스훈스
2019. 6. 2. 19:02
1. 문제
2. 문제풀이
n=1일때부터 n=4일때까지 그려보고 d[n]=d[n-2]+d[n-1] 규칙을 찾을 수 있었다.
이때, n<=2일 경우는 예외처리를 해주었다.
3. 소스코드
import java.util.Scanner;
public class Main {
public static int[] d;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
d = new int[1001];
System.out.println(solve(n));
}
public static int solve(int n) {
if (n == 1 || n == 2) {
d[n] = n % 10007;
return d[n];
} else {
for (int i = 1; i <= n; i++) {
if (i == 1) {
d[i] = 1;
} else if (i == 2) {
d[i] = 2;
} else {
d[i] = d[i - 2] + d[i - 1];
d[i] %= 10007;
}
}
}
return d[n];
}
}