-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
43 lines (34 loc) · 942 Bytes
/
Main.java
File metadata and controls
43 lines (34 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class Main {
static int N;
static int[] T, P;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
T = new int[N];
P = new int[N];
for(int i=0; i<N; i++){
T[i] = sc.nextInt();
P[i] = sc.nextInt();
}
int max = dfs(0);
System.out.println(max);
sc.close();
}
public static int dfs(int day){
// 마지막 날 이후에는 상담 못함
if(day >= N){
return 0;
}
int money = 0;
// 1. 상담을 진행할 경우
if(day + T[day] <= N){
money = Math.max(money, dfs(day+T[day]) + P[day]);
}
// 2. 상담을 진행하지 않은 경우, 하루 추가
if(day + 1 < N){
money = Math.max(money, dfs(day+1));
}
return money;
}
}