第15章动态规划.ppt

第15章动态规划

* * * * * * * * * * * * * * * * * * * * * yMax=min(w[n]-1,c) * * * * TraceBack For i=1 to n-1 If xi from P(i+1) then xi=1 else xi=0 * * * * * * * * * * * * * * * * * * * * * * * * * * * Constructing an LCS PrintLCS(b,X,i,j) 1. i=m 2. j=n; 3. if i==0 or j==0 then exit; 4. if b[i,j]==1 then { i=i-1; j=j-1; print “xi”; } 5. if b[i,j]==2 i=i-1 6. if b[i,j]==3 j=j-1 7. Goto Step 3. The time complexity: O(nm). 0 1 2 3 4 i Xi A B C Yj B B A C D 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 3 B B C B LCS (reversed order): B C B LCS (str

文档评论(0)

1亿VIP精品文档

相关文档