From d639e78b4c8cb51b83abc0ec79c284890751cc0d Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 5 Aug 2025 23:01:55 +0900 Subject: [PATCH] =?UTF-8?q?[20250805]=20BOJ=20/=20G5=20/=20=EC=88=98?= =?UTF-8?q?=EA=B0=95=20=EA=B3=BC=EB=AA=A9=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 --- ...0\352\260\225 \352\263\274\353\252\251.md" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "suyeun84/202508/05 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" diff --git "a/suyeun84/202508/05 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" "b/suyeun84/202508/05 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" new file mode 100644 index 00000000..2ce74924 --- /dev/null +++ "b/suyeun84/202508/05 BOJ G5 \354\210\230\352\260\225 \352\263\274\353\252\251.md" @@ -0,0 +1,35 @@ +```java +import java.io.*; +import java.util.*; + +public class boj17845 { + 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 StringBuilder sb = new StringBuilder(); + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + int K = nextInt(); + int[] prior = new int[K+1]; + int[] time = new int[K+1]; + int[][] bag = new int[K+1][N+1]; + + for (int i = 1; i <= K; i++) { + nextLine(); + prior[i] = nextInt(); + time[i] = nextInt(); + } + + for (int i = 1; i <= K; i++) { + for (int j = 1; j <= N; j++) { + if (time[i] <= j) bag[i][j] = Math.max(bag[i-1][j], bag[i-1][j-time[i]] + prior[i]); + else bag[i][j] = bag[i-1][j]; + } + } + System.out.println(bag[K][N]); + } +} +```