2×n 타일링 11726

LJM·2023년 3월 18일
0

백준풀기

목록 보기
146/259

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

O(N)

1이나 2로 어떤 숫자를 만드는 경우를 구하는것

import java.io.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());//1 ≤ n ≤ 1,000

        long[] dp = new long[Math.max(n+1, 3)];

        dp[1] = 1;
        dp[2] = 2;

        for (int i = 3; i <= n; i++)
        {
            dp[i] = (dp[i-2]+dp[i-1])% 10007L;
        }

        System.out.println(dp[n]);
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글