(define (lcs lst1 lst2)
(define (except-last-pair list)
(if (pair? (cdr list))
(cons (car list) (except-last-pair (cdr list)))
'()))
(define (car-last-pair list)
(if (pair? (cdr list))
(car-last-pair (cdr list))
(car list)))
(if (or (null? lst1) (null? lst2)) null
(if (= (car-last-pair lst1) (car-last-pair lst2))
(append (lcs (except-last-pair lst1) (except-last-pair lst2)) (cons (car-last-pair lst1) '()))
(**if (> (length (lcs lst1 (except-last-pair lst2))) (length (lcs lst2 (except-last-pair lst1))))
(lcs lst1 (except-last-pair lst2))
(lcs lst2 (except-last-pair lst1))))))**
我不希望它一遍又一遍地跑..如何改善这种算法(LCS)
问候, Superguay
你能否描述它的功能以及为什么你会发现它目前很糟糕。 – ponzao 2010-04-08 05:48:27