코딩/백준 알고리즘
11726번) 2×n 타일링
금손형아
2017. 10. 9. 21:45
문제 출처 : https://www.acmicpc.net/problem/11726
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int input = scanner.nextInt(); calResult(input); } static void calResult(int value) { int temp1 = 1; int temp2 = 2; if ( value == 1 ) { System.out.println(temp1); } else if (value == 2 ) { System.out.println(temp2); } else { for (int i=3; i <= value; i++) { int temp = temp1 + temp2; temp1 = temp2; temp2 = temp % 10007; } System.out.println(temp2); } } } |
다이나믹 프로그래밍은 규칙을 찾는게 문제인거 같네요.
n=1 부터 하나씩 늘려가며 규칙을 찾을 수 밖에 없습니다.
특히 n항 = (n-2)항 + (n-1)항 인 경우가 많은것 같네요.