CLRS 15-1
CLRS 15-2
M - (j-i) - (Li+...+Lj) >= 0 : alignedIdx[i][j] = (M - (j-i) - (Li+...+Lj))^3
M - (j-i) - (Li+...+Lj) < 0 : alignedIdx[i][j] = min(alignedIdx[i][k], alignedIdx[k+1][j]) i<=k<j
CLRS 15-3
c[i][j] = MIN(c[m,n], MIN(c[i,n]+cost(kill))), 0<=i
Gene alignment copy : -1 replace : 1 insert : 2 delete : 2 twiddle : Max kill : Max
//base method and data
type lDCompute interface {
updateCost(int, int, *lDComputor) (int)
preOpIdx(int, int, *lDComputor) (int, int)
}
type lDOperation struct {
name string
cost int
lDCompute
}
func (op *lDOperation)init(name string, cost int)(*lDOperation) {
op.name = name
op.cost = cost
return op
}
//operations
type copy struct {
lDOperation//base
}
func (c *copy)init(cost int)(*copy) {
op:=c.lDOperation.init("copy", cost)
op.lDCompute = c
return c
}
func (c *copy) updateCost(i int, j int, ldc *lDComputor) (int) {
//...
}
func (c *copy) preOpIdx(i int, j int, ldc *lDComputor) (int, int) {
//...
}
func newCopy(cost int)(*copy) {
return new(copy).init(cost)
}
//object
copyObj := newCopy(1)
//base type pointer
var op *lDOperation
op = &newCopy(1).lDOperation
CLRS 15-6
score[i][j] = max(score[i-1][j-1],score[i-1][j],score[i-1][j+1]) + board[i][j]