From e4dc9f52235f82fe5d25653325f392879734dc4a Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sat, 21 Jun 2025 20:29:23 +0900 Subject: [PATCH] =?UTF-8?q?[20250621]=20BOJ=20/=20G4=20/=20=ED=98=B8?= =?UTF-8?q?=ED=85=94=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../21 BOJ G4 \355\230\270\355\205\224.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "suyeun84/202506/21 BOJ G4 \355\230\270\355\205\224.md" diff --git "a/suyeun84/202506/21 BOJ G4 \355\230\270\355\205\224.md" "b/suyeun84/202506/21 BOJ G4 \355\230\270\355\205\224.md" new file mode 100644 index 00000000..a0b694d0 --- /dev/null +++ "b/suyeun84/202506/21 BOJ G4 \355\230\270\355\205\224.md" @@ -0,0 +1,33 @@ +```java +import java.io.*; +import java.util.*; + +public class boj1106 { + 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 C = nextInt(); + int N = nextInt(); + int[] dp = new int[C+100]; + int answer = Integer.MAX_VALUE; + Arrays.fill(dp, Integer.MAX_VALUE); + dp[0] = 0; + for (int i = 0; i < N; i++) { + nextLine(); + int cost = nextInt(); + int num = nextInt(); + for (int j = num; j < C+100; j++) { + if (dp[j - num] != Integer.MAX_VALUE) { + dp[j] = Math.min(dp[j], dp[j-num] + cost); + } + } + } + for (int i = C; i < C+100; i++) answer = Math.min(answer, dp[i]); + System.out.println(answer); + } +} +```