delpho

[실버3, DP] 백준 11726 - 2xn 타일링 (자바) 본문

알고리즘/DP

[실버3, DP] 백준 11726 - 2xn 타일링 (자바)

delpho 2024. 3. 3. 23:02

Think

1. 점화식을 잘못 찾아서 틀렸다.

2. https://yinq.tistory.com/68 를 참고하여 풀었다.

3. 예제를 활용하여 점화식을 검토하는 방법이 있다.

4. 문제를 여러 개 풀면서 여러 점화식을 접해보자.

 

 

제출 코드

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

public class Main {
    static int n;
    static Integer dp[];

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        init();
        progress();
    }

    private static void progress() {
        dp = new Integer[n + 2];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 2;

        System.out.println(recursion(n));
    }

    private static int recursion(int n) {

        if(dp[n] == null){
            dp[n] = (recursion(n-1) + recursion(n-2)) % 10007;
        }

        return dp[n];

    }

    private static void init() throws IOException {
        n = Integer.parseInt(br.readLine());
    }

}