Skip to content

Latest commit

 

History

History

dp

Double adjustable Euclidean traveling salesman


CLRS 15-1


Code

Test


Solution:


Pretty Print


CLRS 15-2


Code

Test


Solution:

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


Levenshtein Distance


CLRS 15-3


Code

Test


Solution:

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

OOP pattern:

//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

Chess Game


CLRS 15-6


Code

Test


Solution:

score[i][j] = max(score[i-1][j-1],score[i-1][j],score[i-1][j+1]) + board[i][j]