본문 바로가기
알고리즘 & 자료구조/백준

백준 24416

by 신재권 2022. 6. 26.
package baekjoon.DP;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main24416 {

   static int A, B;
   static int[] memo;

   public static void main(String[] args) throws Exception {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int N = Integer.parseInt(br.readLine());
      memo = new int[N + 1];
      fibonacci(N);
      fibonacci_dp(N);
      System.out.printf("%d %d", A, B);
   }

   private static int fibonacci_dp(int n) {
      memo[1] = memo[2] = 1;
      for (int i = 3; i <= n; i++) {
         B++;
         memo[i] = memo[i - 1] + memo[i - 2];
      }
      return memo[n];
   }

   private static int fibonacci(int n) {
      if (n == 1 || n == 2) {
         A++;
         return 1;
      }
      return fibonacci(n - 1) + fibonacci(n - 2);
   }

}

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 9184  (0) 2022.06.27
백준 2525  (0) 2022.06.26
백준 7569  (0) 2022.06.22
백준 1012  (0) 2022.06.20
백준 7576  (0) 2022.06.20