-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10891.cpp
executable file
·46 lines (45 loc) · 1.04 KB
/
P10891.cpp
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
int main() {
int N, a[101][100]; // size 1..100, start 0..99
while(true) {
cin >> N;
if(N == 0)
return 0;
FORI(N) {
cin >> a[0][i];
//cerr << a[0][i] << " ";
}
//cerr << endl;
for(int size = 2; size <= N; ++size) {
for(int pos = 0; pos + size <= N; ++pos) {
// Best is first taking all!
int best = 0;
FORI(size)
best += a[0][pos+i];
// Try to improve best:
int fromLeft = 0;
for(int left = 1; left < size; ++left) {
fromLeft += a[0][pos+left-1];
int newScore = fromLeft - a[size-left-1][pos+left];
if(newScore > best) {
//cerr << "<";
best = newScore;
}
}
// Again from right:
int fromRight = 0;
for(int right = 1; right < size; ++right) {
fromRight += a[0][size+pos-right];
int newScore = fromRight - a[size-right-1][pos];
if(newScore > best) {
//cerr << ">";
best = newScore;
}
}
a[size-1][pos] = best;
//cerr << best << " ";
} // for pos
//cerr << endl;
} // for size
cout << a[N-1][0] << endl;
} // while(true)
} // int main