最长递增子序列(LIS)
(defun tt(lst)(defun f1 (plst j num)
(setq ij -1)
(setq plst (mapcar '(lambda (x) (if (= (setq ij (+ ij 1)) j) num x)) plst))
)
(setq n (length lst) i 0 ans 0 vlst '(nil))
(repeat n (setq vlst (cons nil vlst)))
(while (< i n)
(setq l 0 r ans)
(while (< l r)
(setq mid (/ (+ l r) 2))
(if (<= (nth mid vlst) (nth i lst))
(setq l (+ mid 1))
(setq r mid)
)
)
(setq vlst (f1 vlst l (nth i lst)))
(if (= l ans) (setq ans (+ ans 1)))
(setq i (+ i 1))
)
(setq vlst (reverse (vl-remove nil vlst)) alst (reverse lst) blst (list (+ 1 (car vlst))))
(whilevlst
(if (and (>= (car alst) (car vlst)) (<= (car alst) (car blst)))
(progn
(setq blst (cons (car alst) blst))
(setq vlst (cdr vlst))
(setq alst (cdr alst))
)
(setq alst (cdr alst))
)
)
(reverse (cdr (reverse blst)))
)
_$ (tt '(0 0 2 4 1 5 1 3 1 2 0 8 9 10 4 6))
(0 0 1 1 1 2 8 9 10)
_$(tt '(0 0 2 4 1 5 1 3 1 2 0 8 9 10 4 6 7))
(0 0 1 1 1 2 4 6 7)
_$ (tt '(5 1 3 2 0 8 9 10 4 6 7))
(1 2 4 6 7)
_$ (tt '(3 5 4 6 10 0 1 9 8 2 7))
(0 1 2 7)
_$ (tt '(0 1 9 10 2 3 4 5 6 8 7))
(0 1 2 3 4 5 6 7)
_$ (tt '(6 1 0 3 11 10 4 5 8 9 2 7))
(0 3 4 5 8 9)
_$
不知用于何处啊
大师 ynhh 发表于 2022-3-14 13:17
不知用于何处啊
大师
书到用时方恨少 赞赞赞
各类算法的LSP实现,明经是大本营
页:
[1]