mình đang làm 1 bài báo cáo về lập trình, mình chưa có hướng giải, mong các bác giúp mình với!! sau đây là đề bài toán: Matrix Chain Multiplication 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. [FONT="]Input Specification[/FONT] Input consists of two parts: a list of matrices and a list of expressions. The first line of the input file contains one integer n ( ), representing the number of matrices in the first part. The next n lines 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): [FONT="]SecondPart = Line { Line } <EOF>[/FONT] [FONT="]Line = Expression <CR>[/FONT] [FONT="]Expression = Matrix | "(" Expression Expression ")"[/FONT] [FONT="]Matrix = "A" | "B" | "C" | ... | "X" | "Y" | "Z"[/FONT] [FONT="]Output Specification[/FONT] 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. [FONT="]Sample Input[/FONT] [FONT="]9[/FONT] [FONT="]A 50 10[/FONT] [FONT="]B 10 20[/FONT] [FONT="]C 20 5[/FONT] [FONT="]D 30 35[/FONT] [FONT="]E 35 15[/FONT] [FONT="]F 15 5[/FONT] [FONT="]G 5 10[/FONT] [FONT="]H 10 20[/FONT] [FONT="]I 20 25[/FONT] [FONT="]A[/FONT] [FONT="]B[/FONT] [FONT="]C[/FONT] [FONT="](AA)[/FONT] [FONT="](AB)[/FONT] [FONT="](AC)[/FONT] [FONT="](A(BC))[/FONT] [FONT="]((AB)C)[/FONT] [FONT="](((((DE)F)G)H)I)[/FONT] [FONT="](D(E(F(G(HI)))))[/FONT] [FONT="]((D(EF))((GH)I))[/FONT] [FONT="]Sample Output[/FONT] [FONT="]0[/FONT] [FONT="]0[/FONT] [FONT="]0[/FONT] [FONT="]error[/FONT] [FONT="]10000[/FONT] [FONT="]error[/FONT] [FONT="]3500[/FONT] [FONT="]15000[/FONT] [FONT="]40500[/FONT] [FONT="]47500[/FONT] [FONT="]15125[/FONT][FONT="][/FONT]
Lại là ma trận. đề khó đấy, để mình xem thử có làm được không đã. Bạn làm báo cáo này ở đâu vậy ? Nhắc nhở: đặt tiêu đề phù hợp, không post 2 bài cùng nội dung.