Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21.07.20 - [BOJ] 15988. 1, 2, 3 더하기 3 #135

Closed
suhyunsim opened this issue Jul 20, 2021 · 0 comments
Closed

21.07.20 - [BOJ] 15988. 1, 2, 3 더하기 3 #135

suhyunsim opened this issue Jul 20, 2021 · 0 comments
Assignees
Labels
DP 다이나믹 프로그래밍 성공 맞은 문제 실버 BOJ - 실버

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Jul 20, 2021

문제

핵심 아이디어

  • d[n] long 배열로 해야 함.

어려운 점, 실수

풀이

package main.java.com.poogle.BOJ.Q15988;

import java.util.Scanner;

public class Main {
    static final int LIMIT = 1000000 ;
    static final long MOD = 1000000009L ;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long[] d = new long[LIMIT + 1];
        d[0] = 1;
        int t = sc.nextInt();
        for (int i = 0; i <= LIMIT; i++) {
            for (int j = 1; j <= 3; j++) {
                if (i - j >= 0) {
                    d[i] += d[i - j];
                }
            }
            d[i] %= MOD;
        }
        while (t-- > 0) {
            int n = sc.nextInt();
            System.out.println(d[n]);
        }
    }
}
@suhyunsim suhyunsim added 실버 BOJ - 실버 DP 다이나믹 프로그래밍 labels Jul 20, 2021
@suhyunsim suhyunsim self-assigned this Jul 20, 2021
@suhyunsim suhyunsim modified the milestone: 7월 3주 차 Jul 20, 2021
@suhyunsim suhyunsim added this to the 7월 4주 차 milestone Jul 20, 2021
@suhyunsim suhyunsim added the 성공 맞은 문제 label Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DP 다이나믹 프로그래밍 성공 맞은 문제 실버 BOJ - 실버
Projects
None yet
Development

No branches or pull requests

1 participant