-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_14501
More file actions
42 lines (35 loc) · 1.08 KB
/
BAEKJOON_14501
File metadata and controls
42 lines (35 loc) · 1.08 KB
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
import java.io.*;
import java.util.*;
public class Main {
static int[] t;
static int[] p;
static int ans=0;
static int N;
public static void recursion(int day, int sum){
if(day==N+1){
if(ans<sum)ans=sum;
return;
}
if(day>N+1){
return;
}
recursion(day+1,sum);
recursion(day + t[day], sum + p[day]);
}
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
N = Integer.parseInt(br.readLine());
t=new int[N+1]; //N=7이면 배열은 크기가 8
p=new int[N+1];
StringTokenizer st;
for(int i=1; i<=N; i++){
st= new StringTokenizer(br.readLine());
t[i] = Integer.parseInt(st.nextToken());
p[i] = Integer.parseInt(st.nextToken());
}
recursion(1,0);
bw.write(String.valueOf(ans));
bw.flush();bw.close();
}
}