From 3d75c99af905c8c03f370006c4f78d8e8a507364 Mon Sep 17 00:00:00 2001 From: wonjunYou Date: Sun, 28 Jul 2024 18:51:44 +0900 Subject: [PATCH] 2024-07-27 --- wonjunYou/README.md | 9 +-- .../BOJ_\354\236\205\353\214\200.java" | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 "wonjunYou/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/BOJ_\354\236\205\353\214\200.java" diff --git a/wonjunYou/README.md b/wonjunYou/README.md index e96b0652..3af91c21 100644 --- a/wonjunYou/README.md +++ b/wonjunYou/README.md @@ -1,6 +1,7 @@ ## ✏️ 기록 -| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | -|:---:|:---------:|:--------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------:| -| 1차시 | 2024.7.17 | 스택 | 주식 가격 | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/121 | -| 2차시 | 2024.7.20 | 슬라이딩 윈도우 | 도둑 | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/128 | +| 차시 | 날짜 | 문제유형 | 링크 | 풀이 | +|:---:|:---------:|:----------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------:| +| 1차시 | 2024.7.17 | 스택 | 주식 가격 | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/121 | +| 2차시 | 2024.7.20 | 슬라이딩 윈도우 | 도둑 | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/128 | +| 3차시 | 2024.7.24 | 다이나믹 프로그래밍 | 성냥개비 | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/132 | diff --git "a/wonjunYou/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/BOJ_\354\236\205\353\214\200.java" "b/wonjunYou/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/BOJ_\354\236\205\353\214\200.java" new file mode 100644 index 00000000..403a78f5 --- /dev/null +++ "b/wonjunYou/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/BOJ_\354\236\205\353\214\200.java" @@ -0,0 +1,60 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + public static void main(String[] args) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + + String[] data = reader.readLine().split(" "); + int N = Integer.parseInt(data[0]); + int M = Integer.parseInt(data[1]); + + int[] scores = new int[N + 1]; + + data = reader.readLine().split(" "); + for (int i = 1; i <= N; i++) { + scores[i] = Integer.parseInt(data[i - 1]); + } + + // 세 번째 줄 입력 처리 + data = reader.readLine().split(" "); + int A = Integer.parseInt(data[0]); + int D = Integer.parseInt(data[1]); + + reader.close(); + + int upper = (N + D - 1) / D; // 최대 헌혈 가능 횟수 + + int[][] dp = new int[upper + 1][N + D]; + + for (int i = 1; i <= N; i++) { + for (int j = 0; j <= upper; j++) { + if (j != 0 && dp[j][i - 1] == 0) continue; + + dp[j][i] = Math.max(dp[j][i], dp[j][i - 1] + scores[i]); + + if (j != upper) { + dp[j + 1][i + D - 1] = Math.max(dp[j + 1][i + D - 1], dp[j][i - 1] + A); + } + } + } + + for (int i = 0; i <= upper; i++) { + int maxScore = 0; + + for (int j = 0; j < dp[i].length; j++) { + maxScore = Math.max(maxScore, dp[i][j]); + } + + if (maxScore >= M) { + System.out.println(i); + return; + } + + } + + System.out.println(-1); + } + +}