Let the sequence of dimensions be p=⟨p0,p1,p2,p3,p4⟩=⟨10,5,20,10,5⟩.
Using dynamic programming for Matrix Chain Multiplication, let m[i,j] denote the minimum number of scalar multiplications needed to compute Ai…Aj:
Chains of length 1:
m[1,1]=m[2,2]=m[3,3]=m[4,4]=0
Chains of length 2:
m[1,2]=p0p1p2=10×5×20=1000
m[2,3]=p1p2p3=5×20×10=1000
m[3,4]=p2p3p4=20×10×5=1000
Chains of length 3:
For m[1,3]:
Split at k=1: m[1,1]+m[2,3]+p0p1p3=0+1000+10×5×10=1500
Split at k=2: m[1,2]+m[3,3]+p0p2p3=1000+0+10×20×10=3000
m[1,3]=1500
For m[2,4]:
Split at k=2: m[2,2]+m[3,4]+p1p2p4=0+1000+5×20×5=1500
Split at k=3: m[2,3]+m[4,4]+p1p3p4=1000+0+5×10×5=1250
m[2,4]=1250
Chain of length 4 (m[1,4]):
Split at k=1: m[1,1]+m[2,4]+p0p1p4=0+1250+10×5×5=1250+250=1500
Split at k=2: m[1,2]+m[3,4]+p0p2p4=1000+1000+10×20×5=2000+1000=3000
Split at k=3: m[1,3]+m[4,4]+p0p3p4=1500+0+10×10×5=1500+500=2000
The minimum cost is min(1500,3000,2000)=1500, corresponding to the parenthesization A1((A2A3)A4).