Number Picking Game
Time limit1sMemory limit256 MB
Ahyeon removes interior numbers one at a time, scores each pick plus its live neighbors, and maximizes the total score.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Intervals
- Solved
- No attempts yet
Problem
Ahyeon plays a keyboard instrument, so Ahyeon builds up fingertip strength with a game about picking numbers. The rules are these.
Ahyeon is given a list of positive integers. Ahyeon can choose any number in the list except the first one and the last one. The chosen number disappears from the list, and the score goes up by the sum of the chosen number and the two numbers next to it. The game ends when only two numbers are left in the list.
Take the list 1 2 3 4 5. If Ahyeon picks 3, the score becomes and the list is 1 2 4 5. If Ahyeon then picks 4, the score becomes and the list is 1 2 5.
Given the list, find the highest score Ahyeon can reach.
Input
The input holds several test cases. Each test case is one line of the form . Here is the count of numbers in the list and . Each integer satisfies . The last line holds a single , and reading that line ends the input.
Output
For each test case, print the highest score Ahyeon can reach on its own line.