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

백준 1003

by 신재권 2022. 3. 21.
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main1003 {

   public static int[] zero = new int[41];
   public static int[] one = new int[41];

   public static void main(String[] args) throws Exception {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int T = Integer.parseInt(br.readLine());

      zero[0] = 1;
      one[1] = 1;
      // O(N) 
      for (int i = 2; i < 41; i++) {
         zero[i] = zero[i - 1] + zero[i - 2];
         one[i] = one[i - 1] + one[i - 2];
      }

      while (T-- > 0) {
         int n = Integer.parseInt(br.readLine());
         System.out.println(zero[n] + " " + one[n]);
      }
   }

}

 

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

백준 2630  (0) 2022.04.10
백준 2798_1  (0) 2022.03.22
백준 14889  (0) 2022.03.13
백준 1157_1  (0) 2022.03.11
백준 18108  (0) 2022.03.10