Data structure matrix multiplication guidance

CSDN Q & A 2022-01-15 01:49:23

Realize the matrix multiplication algorithm . Input n The dimension of a matrix (n+1 Number , n>2), Output the minimum number of times and order of matrix multiplication , That is, the way the matrix is bracketed , Such as : (A1((A2A3)A4)).

Submission format :
Realization void solve(int n,int p[],int out[]) function .
Parameters n Is the number of matrices ,p Is about the dimension of the matrix n+1 Number , matrix Ai The dimension of is (p[i-1],p[i]),out[0] Multiply the minimum number of times MOD1000000007,out[i] Is the concatenation order of the output (i>0).2<n<=500,2<p[i]<=500.
When outputting the concatenation order , Please put ( Replace with -1、) Replace with -2, matrix Ai Replace with i, Output to out Array .
Please do not printf Output anything .

sample input :
n=5,p={10,5,2,8,6,3}
sample output :
out={292,-1,-1,1,2,-2,-1,-1,3,4,-2,5,-2,-2}


thank
Similar articles

2022-01-15

2022-01-15

2022-01-15