#P1753. 矩阵链排序问题
矩阵链排序问题
Problem Description
Given matrices, the -th matrix has size rows and columns, and we do not care about their contents. We consider multiplying them in order (called the chain product):
Matrix multiplication is not commutative, but it is associative. Therefore, by choosing a good order of association, we can reduce the number of operations as much as possible. In this problem, we define that multiplying a matrix of size by a matrix of size requires operations.
Please compute the minimum number of operations needed to compute the chain product of the given matrices. For convenience, you do not need to construct the optimal order.
Input Format
The first line contains a positive integer , representing the number of matrices.
The next line contains positive integers. The -th integer is , with the meaning described above.
Output Format
Output one integer, representing the minimum number of operations.
3
5 3 2 6
90
Hint
Sample explanation: The sample tells us that there are matrices, with sizes , , and . Consider the two possible multiplication orders:
- Multiply and first to get a matrix, then multiply it by . The number of operations is .
- Multiply and first to get a matrix, then multiply it by . The number of operations is .
This problem asks for the minimum number of operations, so the answer is .
Constraints: For all testdata, , . Specifically:
- For of the testdata, .
- For another of the testdata, .
Input Format
{{formatI}}
Output Format
{{formatO}}
Hint
{{hint}}
Translated by ChatGPT 5