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.13 - [BOJ] 10844. 쉬운 계단 수 #128

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

21.07.13 - [BOJ] 10844. 쉬운 계단 수 #128

suhyunsim opened this issue Jul 13, 2021 · 0 comments
Assignees
Labels
DP 다이나믹 프로그래밍 실버 BOJ - 실버 실패 시도했지만 맞지 못한 문제

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • 계단 수: 인접한 자리의 차이가 1이 나는 수
  • D[i][j] = 길이가 i인 계단수 마지막 자리가 j인 개수
    • D[i][j] = D[i - 1][j- 1] + D[i -1][j + 1] (1 <= j <=8)
    • j가 0이라면? j+1만 올 수 있음
    • j가 9라면? j-1만 올 수 있음
  • D[1][1] ~ D[1][9] -> 1
  • D[1][0] = 0 (조건 때문)

어려운 점, 실수

풀이

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

import java.util.Scanner;

public class Main {
    static final long MOD = 1000000000L;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] d = new long[n + 1][11];
        for (int i = 1; i <= 9; i++) {
            d[1][i] = 1;
        }
        for (int i = 2; i <= n; i++) {
            for (int j = 0; j <= 9; j++) {
                d[i][j] = 0;
                if (j - 1 >= 0) {
                    d[i][j] += d[i - 1][j - 1];
                }
                if (j + 1 <= 9) {
                    d[i][j] += d[i - 1][j + 1];
                }
                d[i][j] %= MOD;
            }
        }
        long ans = 0;
        for (int i = 0; i <= 9; i++) {
            ans += d[n][i];
        }
        ans %= MOD;
        System.out.println(ans);
    }
}
@suhyunsim suhyunsim added 실패 시도했지만 맞지 못한 문제 실버 BOJ - 실버 DP 다이나믹 프로그래밍 labels Jul 13, 2021
@suhyunsim suhyunsim added this to the 7월 3주 차 milestone Jul 13, 2021
@suhyunsim suhyunsim self-assigned this Jul 13, 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