🐣 알고리즘 삐약/💻 백준 삐약

76 삐약 : 백준 1003| 피보나치 함수 [바킹독 문제 풀이|DP|JAVA]

우주수첩 2024. 6. 17. 15:50
728x90

https://www.acmicpc.net/problem/1003

 

package BKD_0x10_DP;

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

public class BOJ_1003 {
    static Integer[][] dp = new Integer[41][2];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(br.readLine());

        dp[0][0] =1;
        dp[0][1] =0;
        dp[1][0] =0;
        dp[1][1] =1;

        while(T-->0){

            int N = Integer.parseInt(br.readLine());


            fibonacci(N);
            System.out.println(dp[N][0]+" "+dp[N][1]);

        }

    }
    static Integer[] fibonacci(int n){
        if(dp[n][0] == null || dp[n][1] == null){
            dp[n][0] = fibonacci(n-1)[0]  + fibonacci(n-2)[0];
            dp[n][1] = fibonacci(n-1)[1]  + fibonacci(n-2)[1];

        }
        return dp[n];
    }
}

 

 

참고 URL : https://st-lab.tistory.com/124

 

[백준] 1003번 : 피보나치 함수 - JAVA [자바]

www.acmicpc.net/problem/1003 1003번: 피보나치 함수 각 테스트 케이스마다 0이 출력되는 횟수와 1이 출력되는 횟수를 공백으로 구분해서 출력한다. www.acmicpc.net 문제 이전의 피보나치 수를 풀어보셨다면

st-lab.tistory.com

 

728x90