Discussion:
[Lisp-cn] lisp 最大子段和问题求助!!
yxc
2015-06-07 15:55:28 UTC
Permalink
又被问题卡䜏了前来求助
求最倧子段和


(defun subset-sum1(numberlist capacity)
返回最倧的子段和
numberlist 是蟓入list
capacity 是限制容量
䟋
(subset-sum1 ’(1 2 18 2 2) 20) => 20
(subset-sum1 ’(2 3 11 6) 10) => 9


只甚䞋面的
numbers, symbols, variables
t , nil
defun, let, quote, ', and or not
first rest car cdr cons list append, null, atom
if, cond


自己写了奜久本来以䞺成功了结果发现考虑的䞍对本来写了的其䞭䞀郚分
(defun thre-sum(numberlist capacity)
(if (null numberlist)
0
(if (>= capacity (+ (car numberlist) (thre-sum(cdr numberlist) (- capacity
(car numberlist)))))
(+ (car numberlist) (thre-sum(cdr numberlist) (- capacity (car
numberlist))))
(thre-sum (cdr numberlist) capacity))))


考虑是䞍是应该甚分支限界法。。
求倧神解答谢谢了
--
--
Lisp-cn(Lisp䞭文甚户组)
CLUG http://lisp.org.cn

---
悚收到歀邮件是因䞺悚订阅了 Google 眑䞊论坛的“Lisp-cn(Lisp䞭文甚户组)”矀组。
芁退订歀矀组并停止接收歀矀组的电子邮件请发送电子邮件到lisp-cn+***@googlegroups.com。
芁查看曎倚选项请访问 https://groups.google.com/d/optout。
Loading...