Efficiently generate all combinations (at all depths) whose sum is within a specified range : <p>I have a set of 80 numbers and I would like to find the list of combinations which totals up to a given number. The below code works fine but its takes too long could someone please help me with an enhanced version which would process it faster ?</p>

<pre><code>public void sum_up(List&lt;int&gt; numbers, int target)    
        {
            sum_up_recursive(numbers, target, new List&lt;int&gt;());
        }

        public void sum_up_recursive(List&lt;int&gt; numbers, int target, List&lt;int&gt; partial)
        {
            int s = 0;
            foreach (int x in partial) s += x;

            if (s == target)
                val +=" sum(" + string.Join(",", partial.ToArray()) + ")=" + target + Environment.NewLine;

            if (s == target &amp;&amp; string.Join(",", partial.ToArray()).Contains("130") &amp;&amp;
                string.Join(",", partial.ToArray()).Contains("104"))
            {
                string gg = " sum(" + string.Join(",", partial.ToArray()) + ")=" + target;
                val += " || || sum(" + string.Join(",", partial.ToArray()) + ")=" + target + Environment.NewLine;
            }

            if (s &gt;= target)
                return;

            for (int i = 0; i &lt; numbers.Count; i++)
            {
                List&lt;int&gt; remaining = new List&lt;int&gt;();
                int n = numbers[i];
                for (int j = i + 1; j &lt; numbers.Count; j++) remaining.Add(numbers[j]);

                List&lt;int&gt; partial_rec = new List&lt;int&gt;(partial);
                partial_rec.Add(n);
                sum_up_recursive(remaining, target, partial_rec);
            }
            lblResult.Text = val;                
        }

        private void btnCheck_Click(object sender, EventArgs e)
        {

            string[] vendorVal = txtvendor.Text.Split(',');
            int[] myInts = Array.ConvertAll(vendorVal, s =&gt; int.Parse(s));
            List&lt;int&gt; numbers = myInts.ToList();
            int target = Convert.ToInt32(txtDifference.Text);
            sum_up(numbers, target);

        }
</code></pre>

<p>Any help is appreciated...</p>
