1. 程式人生 > >【hihocoder 1388】【區間DP】A Game【給出一個數列,兩人每次從數列的頭尾取數,小ho 先取,小hi每次都採取最優策略,問小ho最終能取得的數的總和最大是多少】

【hihocoder 1388】【區間DP】A Game【給出一個數列,兩人每次從數列的頭尾取數,小ho 先取,小hi每次都採取最優策略,問小ho最終能取得的數的總和最大是多少】

描述

Little Hi and Little Ho are playing a game. There is an integer array in front of them. They take turns (Little Ho goes first) to select a number from either the beginning or the end of the array. The number will be added to the selecter's score and then be removed from the array.

Given the array what is the maximum score Little Ho can get? Note that Little Hi is smart and he always uses the optimal strategy. 

輸入

The first line contains an integer N denoting the length of the array. (1 ≤ N ≤ 1000)

The second line contains N integers A1A2, ... AN, denoting the array. (-1000 ≤ Ai ≤ 1000)

輸出

Output the maximum score Little Ho can get.

樣例輸入