From 7a34fca08950323bda000aab00bcad12c609ed98 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Thu, 2 Oct 2025 17:22:15 +0900 Subject: [PATCH] =?UTF-8?q?[20251002]=20BOJ=20/=20G4=20/=20=EC=82=AC?= =?UTF-8?q?=ED=83=95=20=EA=B0=80=EA=B2=8C=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\225 \352\260\200\352\262\214.md" | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 "suyeun84/202510/02 BOJ G4 \354\202\254\355\203\225 \352\260\200\352\262\214.md" diff --git "a/suyeun84/202510/02 BOJ G4 \354\202\254\355\203\225 \352\260\200\352\262\214.md" "b/suyeun84/202510/02 BOJ G4 \354\202\254\355\203\225 \352\260\200\352\262\214.md" new file mode 100644 index 00000000..84eafc7a --- /dev/null +++ "b/suyeun84/202510/02 BOJ G4 \354\202\254\355\203\225 \352\260\200\352\262\214.md" @@ -0,0 +1,48 @@ +```java +import java.io.*; +import java.util.*; + +public class boj4781 { + 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()); } + static double nextDouble() { return Double.parseDouble(st.nextToken()); } + + public static void main(String[] args) throws Exception { + while(true) { + nextLine(); + int n = nextInt(); // 사탕 종류의 수 + int m = (int) (nextDouble() * 100); // 상근이 돈 양 + if (n == 0 && m == 0) break; + Candy[] candy = new Candy[n+1]; + for (int i = 1; i <= n; i++) { + nextLine(); + candy[i] = new Candy(nextInt(), (int) (nextDouble() * 100 + 0.5)); + } + System.out.println(solve(n, m, candy)); + } + } + + static private int solve(int n, int m, Candy[] candy) { + int[] dp = new int[m+1]; + for (int i = 1; i <= n; i++) { // 사탕 종류 + int cal = candy[i].c; + int val = candy[i].p; + for (int j = 0; j <= m; j++) { + if (j - val >= 0) dp[j] = Math.max(dp[j], dp[j-val] + cal); + } + } + return dp[m]; + } + + static class Candy { + int c; + int p; + public Candy(int c, int p) { + this.c = c; + this.p = p; + } + } +} +```