给定一组整数,如何找到与给定值相加的子集...子集问题?
Given a set of integers, how to find a subset that sums to a given value...the subset problem ?
示例:S = {1,2 ,4,3,2,5}和n = 7 查找总和为n的可能子集。 我试图google出来找到很多链接,但不清楚。 我们如何在java中解决这个问题,什么是要使用的数据结构及其复杂性?
Example : S = {1,2,4,3,2,5} and n= 7 Finding the possible subsets whose sum is n. I tried to google out found many links,but were not clear. How can we solve this in java and what is the data structure to be used and its complexity ?
推荐答案不要给你任何代码,但是解释它是如何工作的。
I wont give you any code, but explain how it works.
以上方法将评估给定集合的每个可能子集。
The above method will evaluate each possible subset of the given set.
如果值的上限较小,则可以使用动态编程方法。
If the upper limit of the values is small, then Dynamic Programming Approach could be used.
更多推荐
给定的整数集合的子集,其总和为常数N:Java
发布评论