Last active
April 15, 2017 05:10
-
-
Save geoseong/0ba18f3cc468c0721df09823cdeb4040 to your computer and use it in GitHub Desktop.
BaekJoon Algorithm Study : 11726_Tiling_2xn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# 입력 | |
첫째 줄에 n이 주어진다. (1 ≤ n ≤ 1,000) | |
1. 2 | |
2. 9 | |
# 출력 | |
첫째 줄에 2×n 크기의 직사각형을 채우는 방법의 수를 10,007로 나눈 나머지를 출력한다. | |
1. 2 | |
2. 55 | |
*/ | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
int tile_x = Integer.parseInt(br.readLine()); | |
// Dynamic array : 입력된 숫자만큼의 크기 배열 정의 | |
int[] dynamicArr = new int[tile_x]; | |
// 2x1 : 1 , 2x2 : 2 , 2x3 : 3 , 2x4 : 5, 2x5 : 8 | |
// 2xn : (n-1) + (n-2) | |
for(int n=0; n<tile_x; n++){ | |
int cal=0; | |
if(n<1){ | |
cal = 1; | |
} | |
else if(n < 2){ | |
cal = dynamicArr[n-1] + 1; | |
} | |
else{ | |
cal = dynamicArr[n-1] + dynamicArr[n-2]; | |
} | |
// 직사각형을 채우는 방법의 수를 10,007로 나눈 나머지 | |
dynamicArr[n] = cal % 10007; | |
} | |
System.out.println(dynamicArr[tile_x-1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment