-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10835.cpp
More file actions
50 lines (39 loc) · 752 Bytes
/
Copy path10835.cpp
File metadata and controls
50 lines (39 loc) · 752 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
46
47
48
49
50
#include <stdio.h>
#include <algorithm>
using namespace std;
int t, n, a[1001];
int dp[1001][1001];
int ep[1001][1001];
int tol(int s, int e);
int sol(int s, int e) {
if (s > e)
return 0;
if (s == e)
return a[s];
if (dp[s][e])
return dp[s][e];
return (dp[s][e] = max(a[s] + tol(s + 1, e), a[e] + tol(s, e - 1)));
}
int tol(int s, int e) {
if (s >= e)
return 0;
if (ep[s][e])
return ep[s][e];
return (ep[s][e] = min(sol(s + 1, e), sol(s, e - 1)));
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
printf("%d\n", sol(1, n));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = 0;
ep[i][j] = 0;
}
}
}
return 0;
}