1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import java.util.Scanner; public class algo1_1003_fibonacci { private static int[][] arr = new int[41][2]; public static void main(String[] args) { fibonacci(); Scanner scanner = new Scanner(System.in); int testCase = scanner.nextInt(); for(int i=0 ; i<testCase ; i++){ int input = scanner.nextInt(); if(input < 0 && input > 40) input = scanner.nextInt(); System.out.println(arr[input][0] + " " + arr[input][1]); } scanner.close(); } public static void fibonacci(){ arr[0][0] = 1; arr[1][1] = 1; for(int i=2 ; i<=40 ; i++){ arr[i][0] = arr[i-1][0] + arr[i-2][0]; arr[i][1] = arr[i-1][1] + arr[i-2][1]; } } } | cs |
'Algorithm' 카테고리의 다른 글
백준 10828번: 스택 (0) | 2018.07.17 |
---|---|
백준 1260번: DFS와 BFS (0) | 2018.04.18 |
BFS (Breadth-First Search) (0) | 2018.04.12 |
DFS (Depth-First Search) (0) | 2018.04.12 |
Dynamic Programming (다이나믹 프로그래밍) (1) | 2018.04.10 |