1 #include<stdio.h> 2 #include<string.h> 3 const int N = 110; 4 int dp[N][N]; 5 bool v[N][N]; 6 int a[N], n, sum[N]; 7 int min(int a, int b) { 8 return a < b ? a: b; 9 } 10 int dfs(int l, int r) { 11 if(v[l][r]) 12 return dp[l][r]; 13 v[l][r] = 1; 14 int m = 0; 15 for(int i = l + 1; i <= r; ++i) m = min(m, dfs(i, r)); 16 for(int i = r - 1; i >= l; --i) m = min(m, dfs(l, i)); 17 return dp[l][r] = sum[r] - sum[l - 1] - m; 18 } 19 int main() { 20 while(scanf("%d", &n), n) { 21 memset(v, 0, sizeof(v));24 sum[0] = 0; 25 for(int i = 1; i <= n; ++i) { 26 scanf("%d", &a[i]); 27 sum[i] =sum[i - 1] + a[i]; 28 } 29 int ans = dfs(1, n); 30 printf("%d\n", ans - (sum[n] - ans)); 31 } 32 return 0; 33 }