|
||||||||||
Problem H. Store The MatrixTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 447 Accepted Submission(s): 216 Problem Description Given a matrix M with r rows and c columns. It is obviously that we need r × c elements to store this matrix. However, for a specific matrix M, we may be able to represent M as “Matrix-chain multiplication” likes M = A1×A2 · · ·×An, where n ≥ 1 and each Ai is a matrix with size ri×ci. Then we can use (${∑^n}_i=1$ ri×ci) elements to store {A1, A2 . . . , An} instead of storing M directly. We want to know: if we represent M in the optimal way, how many elements are needed at least to store M? Input Input is given from Standard Input in the following format: r c $M_{1,1}$ $M_{1,2}$ ... $M_{1,c}$ $M_{2,1}$ $M_{2,2}$ ... $M_{2,c}$ ... ... ... $M_{r,1}$ $M_{r,2}$ ... $M_{r,c}$ Constraints 1 ≤ r, c ≤ 30 0 ≤ $M_{i,j}$ ≤ 1000(1 ≤ i ≤ r, 1 ≤ j ≤ c) (Note that although all $M_{i,j}$ are non-negative integers in the input,we think the element type is float number with infinity precision and can be negative) . Output Print one integer denotes the minimal number of elements needed Sample Input
Sample Output
Source | ||||||||||
|