===================
Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix multiplication is associative, the order in which multiplications are performed is arbitrary. However,
the number of elementary multiplications needed strongly depends on the evaluation order you choose.
For example, let A be a 50*10 matrix, B a 10*20 matrix and C a 20*5 matrix. There are two different strategies to compute A*B*C, namely (A*B)*C and A*(B*C).
The first one takes 15000 elementary multiplications, but the second one only 3500.
Your job is to write a program that determines the number of elementary multiplications needed for a given evaluation strategy.
Input Specification
Input consists of two parts: a list of matrices and a list of expressions.
The first line of the input file contains one integern(), representing
the number of matrices in the first part. The nextnlines each contain one capital letter, specifying the name of the matrix, and two integers, specifying the number of rows and columns of the matrix.
The second part of the input file strictly adheres to the following syntax (given in EBNF):
SecondPart = Line { Line } <EOF>
Line = Expression <CR>
Expression = Matrix | "(" Expression Expression ")"
Matrix = "A" | "B" | "C" | ... | "X" | "Y" | "Z"
Output Specification
For each expression found in the second part of the input file, print one line containing the word "error" if evaluation of the expression leads to an error due to non-matching matrices. Otherwise
print one line containing the number of elementary multiplications needed to evaluate the expression in the way specified by the parentheses.
Sample Input
9
A 50 10
B 10 20
C 20 5
D 30 35
E 35 15
F 15 5
G 5 10
H 10 20
I 20 25
A
B
C
(AA)
(AB)
(AC)
(A(BC))
((AB)C)
(((((DE)F)G)H)I)
(D(E(F(G(HI)))))
((D(EF))((GH)I))
Sample Output
0
0
0
error
10000
error
3500
15000
40500
47500
15125
===================
相关推荐
在三值光学计算机上进行的矢量乘矩阵运算,金翊,王先超,本文报道一种进行矢量乘矩阵运算的光学方法。这个方法在一种新颖的光学计算结构--三值光学计算机(ternary optical computer,TOC)上,使�
lvds-source-synch-serdes-clock-multiplication.pdf
Source Code for 2009 Supercomputing Paper Implementing Sparse Matrix-Vector Multiplication on Throughput-Oriented Processors
matrix multiplication (see laochanlam/matrix-multiplication in github)
Synchronous-100x100-Matrix-Multiplication-using-Multiple-Threads:开发了一个程序,用于通过使用多个线程将两个大型矩阵相乘。 之后,通过在有效时间内将整个任务划分为不同数量的线程来同步计算结果矩阵
MaskNet:Introducing+Feature-Wise+Multiplication+to+CTR+Ranking+Models+by+Instance-Guided+Mask
矩阵链乘法 该程序找到了最有效的乘法矩阵的方法。 该程序实现的复杂度为O(n ^ 3),并用O(n)括住最终输出 输入规范:第一行包含n,下一行包含a0,...,an,以空格分隔。 假定所有数字都是正数且适合int且n最多为...
Matrix Chain Multiplication is perhaps the quintessential example of dynamic programming. The problem can be stated as follows: given a chain <A1, A2,..., An> of n matrices, where for i = 1, 2,....
用法 $ npm install$ NODE_PATH=node_modules node index.js [DONE] RESET DATABASE[ '[DONE] generate test data: leftMatrix: ', [ { row: 0, column: 0, value: 0, _id: 54a0219b5c38d4e4722b9c8f }, { row: 0, ...
稀疏矩阵乘法 稀疏矩阵乘法
Efficient matrix multiplication
矩阵向量乘法 该算法的描述可以参考 。
矩阵乘法集群 该项目暗示了分布式计算体系结构可以执行矩阵乘法。 该项目的主要依存关系是ZeroMQ。 该程序在IPC机制上运行。 运行程序 请按照以下步骤运行代码 启动服务器: 服务器负责接收来自客户端的请求;...
并行矩阵乘法使用WebWorkers实现并行矩阵乘法
题目描述: 输入n个矩阵的维度和一些矩阵链乘表达式,输出乘法的次数。如果乘法无法进行,输出error。假定A是m*n矩阵,B是n*p矩阵,那么AB是m*p矩阵,乘法次数为m*n*p。如果A的列数和B的行数不同,则乘法无法进行。...
the new algorithm is also faster than the best known matrix multiplication algorithm for dense matrices which uses O(n2:38) algebraic operations. The new algorithm is obtained using a surprisingly ...
struct Matrix { int a, b; Matrix(int a = 0,int b=0):a(a),b(b){} }m[26]; stack s; int main() { int n; cin >> n; for (int i = 0; i > name; int k = name[0] - 'A'; cin >> m[k].a >> m[k].b; } ...
see jaeho3690/Matrix_multiplication_python in github
编写一个程序用于矩阵加法amd矩阵乘法.java 开发商Akshaykumar Talanje