DP思想 之 Matrix-chain multiplication(矩阵链相乘问题)

一.矩阵链复杂度计算(根据两两相乘计算次数):

假设有A1(10*100),A2(100*5),A3(5*50)三个矩阵

((A1A2)A3) 计算顺序使用到的乘法次数为:10*100*5 + 10*5*50=7500次

(A1(A2A3)) 计算顺序使用到的乘法次数为:100*5*50 + 10*100*50=75000次

二.矩阵链相乘组合方式的计算(括号组合的方式):

假设有矩阵链 A1A2A3...An ,组合方式一共有:

三.DP在矩阵链求解中的应用:

Our goal is only to determine an order for multiplying matrices that has the lowest cost. Typically, the time invested in determining this optimal order is more than paid for by the time saved later on when actually performing the matrix multiplications (such as performing only 7500 scalar multiplications instead of 75,000).

即:求出复杂度最低(相乘次数最少)的一种相乘顺序

四.求解步骤:

1.The structure of an optimal parenthesization(描述解的结构)

A(i..j) = A(i) A(i+1) ... A(j)

假设A(i..j) 最优解为子链 A(i..k) 和 A(k+1..j) 相乘, A(i..j) 为最优解的同时, A(i..k) 与 A(k+1..j) 同为最优解

2.A recursive solution(递归方式求解)

用m[i,j]表示计算矩阵A(1..n)最小复杂度,假设矩阵A(i)为一个(i-1)*i的矩阵,行列用P(i-1)和P(i)表示,则A(i..k)A(k+1..j) takes P(i-1)P(k)P(j) scalar multiplications.

m[i,j] = m[i,k]+m[k+1,j]+ Pi-1 Pk Pj

s[i,j] = k

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值