Dynamic Programming II

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

Dynamic Programming II. Michael Tsai (Instructed by TA) 2011/10/07. 連串矩陣相乘問題. 題目 : 求 矩陣相乘之解 . .cols= .rows. Matrix multiplication is associative. 以上算出來答案都一樣. ……. and are compatible. q. r. 連串矩陣相乘問題. q. p. Matrix-Multiply(A,B) if A.columns != B.rows - PowerPoint PPT Presentation

Text of Dynamic Programming II

Data Structure and Algorithm II

Dynamic Programming IIMichael Tsai(Instructed by TA)2011/10/07

23!pqqrpqr4101001005550-56

.dynamic programming:78k991011

? (i,j)

12j-i+1(matrix)problem size13problemproblem...problem sizei,jk

trace code

14MatrixDimension30 x 3535 x 1515 x 55 x 1010 x 2020 x 25

, s

151617?

: dynamic programming?:Optimal substructureOverlapping Subproblems18Optimal substructure?Definition: A problem exhibits optimal substructure if an optimal solution to the problem contains within it optimal solutions to subproblems.optimal substructure?19optimal substructure?(, ), , subproblem., , subproblem, (subproblem)().

20Optimal substructure21

()subproblem, versusOptimal substructure22k!kj-1, Optimal substructure(), dynamic programming algorithm.(Subproblem graphs)23: Overlapping Subproblems: 241..31..12..31..23..32..23..32..21..1overlap!: optimal substructure25: optimal substructure26qrst: optimal substructure27DNA28

?!DNA29

p.391DNA30?31

Dynamic Programming321. Optimal Substructure3334Optimal Substructure35!

Overlapping subproblem36!

Dynamic Programming372. ()if i=0 or j=0, subproblem

Dynamic Programming383.

01230123ijbottom-up0123456000000001000011120111122301122224011223350122233601223347012234439012345601234567BDCABAABCBDAB40: cLCS, bDynamic Programming414. LCS