문제 : https://www.acmicpc.net/problem/14501
코드 제출 : https://www.acmicpc.net/source/28998606
import java.util.*;
public class Main {
static Boolean DEBUG = false;
static int maxi = 0;
static int n = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int[] price = new int[n];
int[] time = new int[n];
for(int i=0 ; i<n ; i++) {
time[i] = sc.nextInt();
price[i] = sc.nextInt();
}
//Integer maxi=0;
getMaxMoney(0,0,price,time);
System.out.println(maxi);
sc.close();
return;
}
static void getMaxMoney(int day,int pay,int[] price, int[] time) {
if(DEBUG) {
System.out.printf("day:%d , pay:%d\n",day, pay);
}
if(n == day) {
maxi = Math.max(maxi,pay);
return;
}
else if(n < day) {
//drop case;
return;
}
else {
//이 일을 하지 않는다
getMaxMoney(day+1,pay,price,time);
//이 일을 한다
getMaxMoney(day+time[day],pay+price[day],price,time);
}
}
}