Optimal matrix-chain multiplication
Dynamic Programming

Answer & solution
Official answer: C
Step through it (12 steps)
Method
The dynamic-programming state M[i,j] is the minimum scalar cost of multiplying the consecutive subchain; a split k adds the costs of its two subchains and their final product. This systematically tests all parenthesizations without a local greedy assumption. In the winning chain, F3F4 first produces 3×1 at cost 48; F2 times that gives 25×1 at cost 75; F1 times that gives 2×1 at cost 50; multiplying F5 costs 2000. Only the first operation multiplies two original matrices directly.
Solution
Use matrix-chain DP: M[i, j]=mink(M[i, k]+M[k+1, j]+d[i−1]d[k]d[j]). Dimensions are 2, 25, 3, 16, 1, 1000. Pair costs are 150, 1200, 48, 16000; three-matrix optimal costs 246, 123, 3048; four-matrix costs 173, 25123. Splitting the full chain after F1, F2, F3, F4 costs 75123, 9198, 48246, 2173 respectively. The unique optimum is((F1(F2(F3F4)))F5), costing 48+75+50+2000=2173. Its only directly multiplied original pair is F3F4, C.

