슈콩

[BOJ] 백준 2293 동전 1 본문

Algorithms/Baekjoon

[BOJ] 백준 2293 동전 1

shukong 2025. 8. 26. 00:18

[문제]

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

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer(br.readLine());
    	int n = Integer.parseInt(st.nextToken());
    	int k = Integer.parseInt(st.nextToken());
    	int[] coin = new int[n+1];
    	for(int i=1;i<=n;i++) {
    		coin[i] = Integer.parseInt(br.readLine());
    	}
    	int[] dp = new int[k+1];
    	dp[0] = 1;
    	for(int i=1;i<=n;i++) {
    		for(int j=coin[i];j<=k;j++) {
    			dp[j] += dp[j-coin[i]];
    		}
    	}
    	System.out.println(dp[k]);
    }
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 2302 극장 좌석  (2) 2025.08.26
[BOJ] 백준 2294 동전 2  (0) 2025.08.26
[BOJ] 백준 2240 자두 나무  (0) 2025.08.25
[BOJ] 백준 2193 이친수  (0) 2025.08.25
[BOJ] 백준 2156: 포도주 시식  (0) 2025.08.25