title: How many ways to get 21 given a list of numbers? How to get all posible combinations of numbers?
body: <p>All right, so I have to solve this problem in which the user gives a list of 7 or <code>k</code> numbers and I have to tell how many ways are there to get <code>21</code> or <code>n</code> using sums and substractions of these numbers. <strong>I have to use all numbers.</strong><br>
  For example, user gives the number: (1 3 4 5 9 1 7). I can put all these numbers into an array of length 7 and count how many times do I get 21 usings sums and/or subs of these numbers: 
  <code>1 +/- 3 +/- 4 +/- 5 +/- 9 +/- 1 +/- 7</code>. </p>
  
  <p>The code for this problem is already made:</p>
  
  <pre><code>count-twenty-one(int* dig, int n, int pos, int sum, int res) {
     if (pos==n) {
         if(sum==21)
           return res++;
     }
     count-twenty-one(dig, n, pos+1, sum+dig[pos], res)
     count-twenty-one(dig, n, pos+1, sum-dig[pos], res)
  }
  </code></pre>
  
  <p>As you can see this makes a DFS (Deep First Search) to find how many ways are there to get 21. Now, the actual problem is how to know how many ways are there to get 21 <strong>using</strong> combinations of given numbers, and again I have to use all of them. For example, user gives the number: </p>
  
  <p><code>(0 0 0 0 2 1 0)</code>. There's no way I can get 21 using 0 + 0 - 0 + 0 + 2 + 1 + 0. But If I append the 2 and the 1 and sum/sub it with the other 0 I can get 21. 
  <code>0 + 0 + 0 - 0 + 21 -0 = 21</code> Let'say the user now gives (2 3 9 8 5 0 7). With this I could for numbers like <code>23 98 5 7</code> and try to see how many ways are there to get the desired number.  But then again I can have <code>239 8 507</code>. </p>
  
  <p>So I guess the main problem is to get all posible combinations of numbers from (1 to k) -<em>K is the length of numbers list</em>- and then use <code>count-twenty-one</code> in all of them. How do I do this? I'm using C++ and arrays.</p>
  
  <p><strong>edit</strong>: </p>
  
  <p>This problem can be solved by gettin all possible paritions of the given array, then putting al those partitions through <code>count-twenty-one</code>. Any ideas?</p>
  
  <p><strong>edit 2</strong>:
  The numbers are 'ordered' this means with <code>(2 3 9 8 5 0 7)</code> I can't form combinations like <code>705 8 93 2</code></p>