Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
子集和-lisp_Lisp_Common Lisp - Fatal编程技术网

子集和-lisp

子集和-lisp,lisp,common-lisp,Lisp,Common Lisp,我想用lisp写一个子集和问题。 示例:(subsetsum'(1 2 3)5)=(2 3),(subsetsum'(1 5 3)2)=无 我只能使用函数 (atom x) (null x) (eq x y) (equal x y) (numberp x) (append x y) (car x) (cdr x) (cons x y) (if x y z) (cond ... ) (let ((x y) (u v)) z) (let* ((x y) (u v)) z) (defun ...

我想用lisp写一个子集和问题。 示例:
(subsetsum'(1 2 3)5)
=
(2 3)
(subsetsum'(1 5 3)2)
=

我只能使用函数

(atom x) 
(null x)
(eq x y)
(equal x y)
(numberp x)
(append x y)
(car x)
(cdr x)
(cons x y) 
(if x y z)
(cond ... ) 
(let ((x y) (u v)) z)
(let* ((x y) (u v)) z)
(defun ...)
(quote x) and its short form 'x
(list x1 x2 ...)
(print ...)
(sort L fun)

我能得到任何提示吗

这个问题的简化推理如下:

  • 您有一个列表
    L
    和一个编号
    S
  • 列表的第一个元素要么是解决方案的一部分,要么不是
  • 如果第一个是解决方案的一部分,那么您需要使用它和更简单问题的解决方案
    (rest L)(-S(first L))
  • 如果它不是解决方案的一部分,那么您需要解决更简单的问题
    (rest L)s
  • 在一些情况下,您可以避免进行搜索。。。例如,如果列表为空且
    S
    不为零,或者如果所有元素都大于零,甚至对所有元素求和,则无法到达
    S