forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3.java
35 lines (29 loc) Β· 1.15 KB
/
3.java
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
import java.util.*;
public class Main {
static int n; // μ 체 μλ΄ κ°μ
static int[] t = new int[15]; // κ° μλ΄μ μλ£νλλ° κ±Έλ¦¬λ κΈ°κ°
static int[] p = new int[15]; // κ° μλ΄μ μλ£νμ λ λ°μ μ μλ κΈμ‘
static int[] dp = new int[16]; // λ€μ΄λλ―Ή νλ‘κ·Έλλ°μ μν 1μ°¨μ DP ν
μ΄λΈ μ΄κΈ°ν
static int maxValue;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 0; i < n; i++) {
t[i] = sc.nextInt();
p[i] = sc.nextInt();
}
// λ°°μ΄μ λ€μμλΆν° κ±°κΎΈλ‘ νμΈ
for (int i = n - 1; i >= 0; i--) {
int time = t[i] + i;
// μλ΄μ΄ κΈ°κ° μμ λλλ κ²½μ°
if (time <= n) {
// μ νμμ λ§κ², νμ¬κΉμ§μ μ΅κ³ μ΄μ΅ κ³μ°
dp[i] = Math.max(p[i] + dp[time], maxValue);
maxValue = dp[i];
}
// μλ΄μ΄ κΈ°κ°μ λ²μ΄λλ κ²½μ°
else dp[i] = maxValue;
}
System.out.println(maxValue);
}
}