Asked by NQuestioner | Textbook Reference: Standard Syllabus
## Solution Approach 1: Standard/Analytical Method ### Approach 1: Top-Down Memoized DP We define the cost function recurrences: $m[i, j] = \min_{i \le k < j} \{ m[i, k] + m[k+1, j] + p_{i-1}p_k p_j \}$ * For $(A_1 A_2)A_3$: $(10 \times 20 \times 30) + (10 \times 30 \times 40) = 6000 + 12000 = 18000$. * For $A_1(A_2 A_3)$: $(20 \times 30 \times 40) + (10 \times 20 \times 40) = 24000 + 8000 = 32000$. * Minimum is $18000$. *Optimized for runtime performance and memory efficiency.*
## Solution Approach 2: Alternative/Algorithmic Method ### Approach 2: Bottom-Up Iterative DP We compute the table values iteratively for chain lengths from $2$ to $N$: ```python for l in range(2, n): for i in range(1, n - l + 1): j = i + l - 1 m[i][j] = min(m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j] for k in range(i, j)) ``` * Both approaches yield $18000$ multiplications with $O(N^3)$ complexity. *This approach provides a secondary verification flow.*