#P63. [KBC005G] Bottles
[KBC005G] Bottles
Source
This problem is adapted from Long Long OJ. All rights reserved.
Problem Description
As we all know, little naive has bottles arranged in a row on a table. The color of the -th bottle is . Each bottle has a spiritual essence, and in each operation, you can choose two adjacent bottles, pay a cost equal to the product of the numerical values of their colors, and change the color of one bottle to match the color of the other.
Now, little naive wants to make all bottles have the same color (with no limit on the number of operations), but the total cost of the operations must be minimized.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
- The first line contains an integer , representing the number of bottles.
- The second line contains integers, where the -th integer is the color of the -th bottle.
Output Format
For each test case, output a single line with an integer representing the minimum total cost.
Samples
1
4
7 4 6 10
92
Sample Explanation
The initial state is :
- First operation: , with a cost of .
- Second operation: , with a cost of .
- Third operation: , with a cost of .
The total cost is .
Data Range
, , .