-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (22 loc) ยท 781 Bytes
/
Copy pathMain.java
File metadata and controls
29 lines (22 loc) ยท 781 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
package DP.P11052;
import java.io.*;
import java.util.*;
public class Main {
static int N;
static int[] P, D;
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/DP/P11052/input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
P = new int[N+1];
D = new int[N+1];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 1; i <= N; i++) P[i] = Integer.parseInt(st.nextToken());
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
D[i] = Math.max(D[i], P[j] + D[i-j]);
}
}
System.out.println(D[N]);
}
}