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.21 - [BOJ] 1309. 동물원 #137

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

21.07.21 - [BOJ] 1309. 동물원 #137

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

Comments

@suhyunsim
Copy link
Owner

suhyunsim commented Jul 21, 2021

문제

핵심 아이디어

  • D[N][M]: 세로로 N칸인 동물원에 배치의 수, 마지막 칸은 M번 방법 사용
    • D[N][0] = N번 줄에 배치하지 않음
      • = D[N - 1][0] + D[N - 1][1] + D[N - 1][2]
    • D[N][1] = N번 줄의 왼쪽에만 배치함
      • = D[N - 1][0] + D[N - 1][2]
    • D[N][2] = N번 줄의 오른쪽에만 배치함
      • = D[N - 1][0] + D[N - 1][1]

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    static final int MOD = 9901;
    static int[][] d;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] d = new int[n + 1][3];
        d[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            d[i][0] = d[i - 1][0] + d[i - 1][1] + d[i - 1][2];
            d[i][1] = d[i - 1][0] + d[i - 1][2];
            d[i][2] = d[i - 1][0] + d[i - 1][1];
            for (int j = 0; j < 3; j++) {
                d[i][j] %= MOD;
            }
        }
        System.out.println((d[n][0] + d[n][1] + d[n][2]) % MOD);
    }

}
@suhyunsim suhyunsim added 실버 BOJ - 실버 DP 다이나믹 프로그래밍 labels Jul 21, 2021
@suhyunsim suhyunsim added this to the 7월 4주 차 milestone Jul 21, 2021
@suhyunsim suhyunsim self-assigned this Jul 21, 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