Matrix Multiplication
Time limit2sMemory limit512 MB
For each prefix of n matrices, decide whether some multiplication order is valid, and if so report the largest possible area of the final product.
- Level
Hard8 of 10
- Topics
- Greedy, Sorting, Implementation, Math
- Solved
- No attempts yet
Problem
You are given matrices . Matrix () has rows and columns ().
For an integer (), you want to compute the value defined as follows.
First, determine whether there is an order in which all matrices can be multiplied. In matrix multiplication, to multiply an matrix by an matrix, we need , and the resulting matrix is . If the matrices cannot be multiplied even when their order is rearranged freely, define . If they can, find the method that makes the final resulting matrix as large as possible, and the size of the resulting matrix (number of rows number of columns) is the value .
Compute .
Input
The first line contains the natural number (). The next lines each contain two integers, the number of rows and the number of columns of each matrix. The number of rows and columns of each matrix is between 1 and 1,000 inclusive.
Output
Output lines in total, and on each line output the value from to .