From c337f8f14e2664610b9946a4919dfe1400b13d9c Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Sun, 23 Nov 2025 23:13:09 +0900 Subject: [PATCH] =?UTF-8?q?[20251123]=20BOJ=20/=20G4=20/=20=EC=84=9C?= =?UTF-8?q?=EC=9A=B8=EC=97=90=EC=84=9C=20=EA=B2=BD=EC=82=B0=EA=B9=8C?= =?UTF-8?q?=EC=A7=80=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...75\354\202\260\352\271\214\354\247\200.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "zinnnn37/202511/23 BOJ G4 \354\204\234\354\232\270\354\227\220\354\204\234 \352\262\275\354\202\260\352\271\214\354\247\200.md" diff --git "a/zinnnn37/202511/23 BOJ G4 \354\204\234\354\232\270\354\227\220\354\204\234 \352\262\275\354\202\260\352\271\214\354\247\200.md" "b/zinnnn37/202511/23 BOJ G4 \354\204\234\354\232\270\354\227\220\354\204\234 \352\262\275\354\202\260\352\271\214\354\247\200.md" new file mode 100644 index 00000000..f672a4f6 --- /dev/null +++ "b/zinnnn37/202511/23 BOJ G4 \354\204\234\354\232\270\354\227\220\354\204\234 \352\262\275\354\202\260\352\271\214\354\247\200.md" @@ -0,0 +1,69 @@ +```java +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BJ_14863_서울에서_경산까지 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N, K, ans; + private static int[][] dp, cost; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + cost = new int[N + 1][4]; + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 4; j++) { + cost[i][j] = Integer.parseInt(st.nextToken()); + } + } + + dp = new int[N + 1][K + 1]; + for (int i = 0; i <= N; i++) { + Arrays.fill(dp[i], -1); + } + dp[0][0] = 0; + } + + private static void sol() throws IOException { + for (int i = 1; i <= N; i++) { + for (int j = 0; j <= K; j++) { + // 도보 선택 + if (j >= cost[i][0] && dp[i - 1][j - cost[i][0]] != -1) { + dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - cost[i][0]] + cost[i][1]); + } + + // 자전거 선택 + if (j >= cost[i][2] && dp[i - 1][j - cost[i][2]] != -1) { + dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - cost[i][2]] + cost[i][3]); + } + } + } + + for (int i = 0; i <= K; i++) { + if (dp[N][i] != -1) { + ans = Math.max(ans, dp[N][i]); + } + } + + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file