-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11052.cpp
More file actions
45 lines (37 loc) · 668 Bytes
/
11052.cpp
File metadata and controls
45 lines (37 loc) · 668 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
44
45
#include <iostream>
using namespace std;
int arr[10001];
int dp[10001];
int max(int a, int b, int c) {
if (a > b) {
if (a > c) return a;
else return c;
}
else if (b > c) {
if (b > c) return b;
else return a;
}
else if (c > a) {
if (c > b) return c;
else return b;
}
}
int main(void) {
int N;
scanf("%d", &N);
fill(dp + 1, dp + N + 1, -1);
for (int i = 1; i <= N; i++) {
scanf("%d", &arr[i]);
}
dp[1] = arr[1];
if (N > 1) {
dp[2] = max(arr[2], dp[1] + dp[1],dp[2]);
for (int i = 3; i <= N; i++) {
for (int j = 1; j <= i / 2; j++) {
dp[i] = max(arr[i], dp[j] + dp[i-j],dp[i]);
}
}
}
printf("%d", dp[N]);
return 0;
}