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.16 - [BOJ] 2225. 합분해 #134

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

21.07.16 - [BOJ] 2225. 합분해 #134

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

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

  • D[K][N] = 0부터 N까지의 정수 K개를 더해서 그 합이 N이 되는 경우의 수
    • = ΣD[K-1][N-L] (0 ≤ L ≤ N)
  • 1개 풀 때 O(N) -> 전체 문제는 KN개 -> O(KN^2)
  • 수 아무것도 사용하지 않았을 때 D[0][0] = 1

어려운 점, 실수

풀이

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

import java.util.Scanner;

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