Adjacent Product Game
Time limit1sMemory limit64 MB
Choose a subsequence of the given numbers to maximize the sum of products of adjacent chosen pairs.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Mirko writes numbers on a very long sheet of paper. Slavko then takes a pencil and crosses out some of them. Every number that is not crossed out is copied to a new sheet in the original order, and Slavko's score is the sum of the products of each pair of neighboring numbers on the new sheet.
For example, if the copied sequence is , then the score is . If fewer than two numbers are copied, the score is .
Slavko does not know which numbers to cross out to reach the highest score. Write a program that finds the largest score Slavko can reach. There is no limit on how many numbers he crosses out.
Input
The first line contains , the count of numbers Mirko wrote. ()
Each of the next lines contains one number from Mirko's paper, written with exactly two decimal digits and padded with a trailing zero when needed. ()
Output
Print the largest score Slavko can reach on the first and only line. Print it with exactly four decimal digits.
Every has two decimal digits, so the score is always a multiple of .