Grouping of elements of set with first n Natural numbers, excluding one arbitrary element, to give us a Sum equal to S

我们两清 提交于 2019-12-13 11:29:34

问题


Array with elements sorted in descending order - l

ans=[]
for t in l:
if t<=S:
    S-=t
    ans.append(t)
if S==0:
    break

ans, Gives us list with selected elements.

Please tell me whether it is satisfiable by all big numbers or not?


回答1:


No it doesn't work for all cases:

For example: S = 17 and l = [10,5,4,3]

The answer and will be: ans = [10,5] and S = 2 (because it didn't get down to 0)

But it could have been solved by: ans [10,4,3]




回答2:


For n=8 and omitted element=2. This won't return the right answer.



来源:https://stackoverflow.com/questions/48169568/grouping-of-elements-of-set-with-first-n-natural-numbers-excluding-one-arbitrar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!