test whether k elements of a set add up to a certain number
Is there a way to determine if k elements of a set add up to a certain number in po开发者_Go百科lynomial time?
How big is the number?
This is a variation on the subset sum problem, which is well-known and NP-complete. However dynamic programming techniques will make it polynomial if the set of possible values that the subsets can take grows polynomially. Which with general integers, isn't true. But with numbers picked from a restricted range happens surprisingly often.
精彩评论