Computing target number from numbers in a set

后端 未结 7 559
太阳男子
太阳男子 2020-12-13 15:14

I\'m working on a homework problem that asks me this:

Tiven a finite set of numbers, and a target number, find if the set can be used to calculate the target number

7条回答
  •  醉梦人生
    2020-12-13 15:35

    pusedo code:

    Works(list, target)
    for n in list
    tmp=list.remove(n)
    return Works(tmp,target+n) or Works(tmp,target-n) or Works(tmp, n-target) or ...
    

    then you just have to put the base case in. I think I gave away to much.

提交回复
热议问题