문제링크
https://www.acmicpc.net/problem/11726
11726번: 2×n 타일링
2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법의 예이다.
www.acmicpc.net
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
BigInteger d[] = new BigInteger[N+1];
if(N>=1) d[1] = new BigInteger("1");
if(N>=2) d[2] = new BigInteger("2");
for(int i=3;i<=N;i++) {
d[i] = d[i-1].add(d[i-2]);
}
System.out.println(d[N].remainder(new BigInteger("10007")));
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_12865_평범한 배낭 (0) | 2021.03.25 |
---|---|
[JAVA]백준_1912_연속합 (0) | 2021.03.24 |
[JAVA]백준_11727_2*N 타일링2 (0) | 2021.03.24 |
[JAVA]백준_9095_1,2,3더하기 (0) | 2021.03.24 |
[JAVA]백준_2748_피보나치수2 (0) | 2021.03.24 |