title: combinational sum calculation issue
body: <p>Working on below problem and post the code. The confusion is, it seems there is no need to check <code>(!target) &amp;&amp; (!need)</code>, and using <code>(!target)</code> itself is fine? But how do we guarantee there are always <strong>exact</strong> k numbers in the results? I tried a few, but it seems working without add condition of <code>&amp;&amp; (!need)</code>. If anyone have any good thoughts, it will be great. Thanks.</p>
  
  <p>Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.</p>
  
  <p>Ensure that numbers within the set are sorted in ascending order.</p>
  
  <p>Example 1:</p>
  
  <p>Input: k = 3, n = 7</p>
  
  <p>Output:</p>
  
  <pre><code>[[1,2,4]]
  </code></pre>
  
  <p>Example 2:</p>
  
  <p>Input: k = 3, n = 9</p>
  
  <p>Output:</p>
  
  <pre><code>[[1,2,6], [1,3,5], [2,3,4]]
  </code></pre>
  
  <p>Code,</p>
  
  <pre><code>class Solution {
  public:
      std::vector&lt;std::vector&lt;int&gt; &gt; combinationSum3(int k, int n) {
          std::vector&lt;std::vector&lt;int&gt; &gt; res;
          std::vector&lt;int&gt; combination;
          combinationSum3(n, res, combination, 1, k);
          return res;
      }
  private:
      void combinationSum3(int target, std::vector&lt;std::vector&lt;int&gt; &gt; &amp;res, std::vector&lt;int&gt; &amp;combination, int begin, int need) {
          if (!target) {
              res.push_back(combination);
              return;
          }
          else if (!need)
              return;
          for (int i = begin; i != 10 &amp;&amp; target &gt;= i * need + need * (need - 1) / 2; ++i) {
              combination.push_back(i);
              combinationSum3(target - i, res, combination, i + 1, need - 1);
              combination.pop_back();
          }
      }
  };
  </code></pre>
  
  <p>thanks in advance,
  Lin</p>