1.问题
“矩阵链乘法,特别要求举例时采用不同于讲义的数据进行推导。”
2.解析
3.设计
示例:P=<20,15,10,25,5,40>, n=5
A1:2015
A2:1510
A3:1025
A4:255
A5:5*40
(1)r=1
l m[1,1]=0;
l m[2,2]=0;
l m[3,3]=0;
l m[4,4]=0;
l m[5,5]=0;
(2)r=2 ,i=1,2,3,4; j=2,3,4,5;
l m[1,2]=201510=3000;
l m[2,3]=151025=3750;
l m[3,4]=10255=1250;
l m[4,5]=25540=5000;
(3)r=3 ,i=1,2,3; j=3,4,5
l m[1,3]=min{ m[1,2]+ m[3,3]+(A1A2)A3, m[1,1]+ m[2,3]+A1(A2A3)};
m[1,2]+ m[3,3]+(A1A2)A3 = 8000
m[1,1]+ m[2,3]+A1(A2A3) = 11250
m[1,3]=8000
s[1,3]=2
l m[2,4]=min{ m[2,3]+ m[4,4]+(A2A3)A4, m[2,2]+ m[3,4]+A2(A3A4)};
m[2,3]+ m[4,4]+(A2A3)A4 = 3750+0+15255=5625
m[2,2]+ m[3,4]+A2(A3A4) = 0+1250+15105=2000
m[2,4]=2000
s[2,4]=2
l m[3,5]=min{ m[3,4]+ m[5,5]+(A3A4)A5, m[3,3]+ m[4,5]+A3(A4A5)};
m[3,4]+ m[5,5]+(A3A4)A5=1250+0+10540=3250
m[3,3]+ m[4,5]+A3(A4A5)=0+5000+102540=10000
m[3,5]=3250
s[3,5]=4
(4)r = 4,i=1,2;j=4,5
l m[1,4]=min{ m[1,1]+ m[2,4]+A1(A2A3A4), m[1,2]+ m[3,4]+(A1A2)(A3A4),
m[1,3]+ m[4,4]+(A1A2A3)A4};
m[1,4]=3500
s[1,4]=1
l m[2,5]=min{ m[2,2]+ m[3,5]+A2(A3A4A5), m[2,3]+ m[4,5]+(A2A3)(A4A5),
m[2,4]+ m[5,5]+(A2A3A4)A5};
m[2,5]=5000
s[2,5]=4
(5)
r=5,i=1; j=5
l
m[1,5]=min{ m[1,1]+ m[2,5]+A1(A2A3A4A5),
m[1,2]+ m[3,5]+(A1A2)( A3A4A5),
m[1,3]+ m[4,5]+ (A1A2A3)(A4A5);
m[1,4]+ m[5,5]+ (A1A2A3A4)A5};
s[1,5]=1
- 分析
5.源码
[github源码地址]
https://github.com/henryzhang6686/myAlgorithmCode/commit/47ded62df1ddb40233a974322f436ecae4debb63