F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem H. Store The Matrix

Time 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
3 3 1 0 1 0 0 0 1 0 1
 

Sample Output
6
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-05 09:08:11, Gzip enabled