동전 1 2293

LJM·2023년 7월 31일
0

백준풀기

목록 보기
210/259

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

DP문제였다.. 점화식 알면 쉬운데 모르면 어려운 문제다

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

        String[] input = br.readLine().split(" ");

        int n = Integer.parseInt(input[0]);
        int k = Integer.parseInt(input[1]);

        int coin;
        int[] dp = new int[10001];
        dp[0] = 1;

        for (int i = 0; i < n; i++) {

            coin = Integer.parseInt(br.readLine());
            for (int j = coin; j <= k; j++) {
                dp[j] += dp[j-coin];
            }
        }

        System.out.println(dp[k]);

    }
}
profile
게임개발자 백엔드개발자

0개의 댓글