From 175a7a7ea7105a61bedc5e7d79bb4db4515bf66a Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 4 Jul 2025 16:32:25 +0900 Subject: [PATCH] =?UTF-8?q?[20250704]=20BOJ=20/=20G4=20/=20=EB=8F=99?= =?UTF-8?q?=EC=A0=84=20=EB=B0=94=EA=BF=94=EC=A3=BC=EA=B8=B0=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\352\277\224\354\243\274\352\270\260.md" | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 "suyeun84/202507/04 BOJ G4 \353\217\231\354\240\204 \353\260\224\352\277\224\354\243\274\352\270\260.md" diff --git "a/suyeun84/202507/04 BOJ G4 \353\217\231\354\240\204 \353\260\224\352\277\224\354\243\274\352\270\260.md" "b/suyeun84/202507/04 BOJ G4 \353\217\231\354\240\204 \353\260\224\352\277\224\354\243\274\352\270\260.md" new file mode 100644 index 00000000..86ef2fa6 --- /dev/null +++ "b/suyeun84/202507/04 BOJ G4 \353\217\231\354\240\204 \353\260\224\352\277\224\354\243\274\352\270\260.md" @@ -0,0 +1,51 @@ +```java +import java.io.*; +import java.util.*; + +public class boj2624 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + public static void main(String[] args) throws Exception { + nextLine(); + int T = nextInt(); + nextLine(); + int k = nextInt(); + Coin[] coins = new Coin[k+1]; + int[][] dp = new int[T+1][k+1]; + + for (int i = 1; i <= k; i++) { + nextLine(); + int p = nextInt(); + int n = nextInt(); + coins[i] = new Coin(p, n); + } + for (int i = 1; i <= k; i++) { + int val = coins[i].val; + int cnt = coins[i].cnt; + dp[0][i - 1] = 1; + + for (int j = 1; j <= cnt; j++) { + for (int z = val * j; z <= T; z++) { + dp[z][i] += dp[z - (val * j)][i - 1]; + } + } + + for (int j = 1; j <= T; j++) { + dp[j][i] += dp[j][i - 1]; + } + } + + System.out.println(dp[T][k]); + } + static class Coin { + int val, cnt; + Coin(int val, int cnt) { + this.val = val; + this.cnt = cnt; + } + } +} +```