Skip to content

Commit

Permalink
Merge pull request #136 from AlgoLeadMe/4-wonjunYou
Browse files Browse the repository at this point in the history
4-wonjunYou
  • Loading branch information
wonjunYou authored Aug 30, 2024
2 parents 542bce0 + 3d75c99 commit ef09710
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
9 changes: 5 additions & 4 deletions wonjunYou/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## ✏️ 기록

| 차시 | 날짜 | 문제유형 | 링크 | 풀이 |
|:---:|:---------:|:--------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------:|
| 1차시 | 2024.7.17 | 스택 | <a href= "https://school.programmers.co.kr/learn/courses/30/lessons/42584">주식 가격</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/121 |
| 2차시 | 2024.7.20 | 슬라이딩 윈도우 | <a href= "https://www.acmicpc.net/problem/13422">도둑</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/128 |
| 차시 | 날짜 | 문제유형 | 링크 | 풀이 |
|:---:|:---------:|:----------:|:------------------------------------------------------------------------------------:|:---------------------------------------------------:|
| 1차시 | 2024.7.17 | 스택 | <a href= "https://school.programmers.co.kr/learn/courses/30/lessons/42584">주식 가격</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/121 |
| 2차시 | 2024.7.20 | 슬라이딩 윈도우 | <a href= "https://www.acmicpc.net/problem/13422">도둑</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/128 |
| 3차시 | 2024.7.24 | 다이나믹 프로그래밍 | <a href= "https://www.acmicpc.net/problem/3687">성냥개비</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/132 |
60 changes: 60 additions & 0 deletions wonjunYou/다이나믹 프로그래밍/BOJ_입대.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit ef09710

Please sign in to comment.