Skip to content

Commit

Permalink
week4_0408 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Kong-E committed Apr 8, 2024
1 parent 29b73bf commit eb6c975
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
23 changes: 18 additions & 5 deletions week4_0408/퇴사.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.*;

public class 퇴사 {
static List<Integer> answers = new ArrayList<>();
static int maxProfit = 0;
public static void main(String[] args) throws IOException {
// i는 1부터 n까지, Ti+i-1까지는 상담 못함(Ti+i부터 상담 가능), Ti+i < n
// 완탐해서 배열에 수익 모두 넣고 max로 출력하기
Expand All @@ -22,14 +22,27 @@ public static void main(String[] args) throws IOException {

recursion(1, n, days, 0);

System.out.println(Collections.max(answers));
System.out.println(maxProfit);
}

public static void recursion(int day, int n, int[][] days, int income) {
if (day > n || day+days[day][0]-1 > n) {
answers.add(income);
// 퇴사 날짜를 넘어가면 종료
if (day > n + 1) {
return;
}
recursion(day+days[day][0], n, days, income + days[day][1]);

// 최대 수익 갱신
if (day == n + 1) {
maxProfit = Math.max(maxProfit, income);
return;
}

// 현재 상담을 선택한 경우
if (day + days[day][0] - 1 <= n) { // 상담 기간이 퇴사 전까지인 경우
recursion(day + days[day][0], n, days, income + days[day][1]);
}

// 현재 상담을 선택하지 않은 경우
recursion(day + 1, n, days, income);
}
}
5 changes: 2 additions & 3 deletions week4_0408/피로도.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public static void main(String[] args) throws IOException {
} else {
if (tired - c >= 0) tired -= c;
else {
while (tired > 0 && c > 0) {
tired -= 1;
c--;
while (tired > 0) {
tired--;
}
}
}
Expand Down

0 comments on commit eb6c975

Please sign in to comment.