title: Find all ways to sum given number (with repetitions allowed) from given set
body: <p>Given an array (e.g. [1,2]) of n elements and a number 'k' (e.g. 6), find all possible ways to produce the sum = k</p>
  
  <p>For given example answer would be  4 because</p>
  
  <pre><code>1 1 1 1 1 1
  1 1 1 1 2
  1 1 2 2
  2 2 2
  </code></pre>
  
  <p>The algorithm I could think of is by brute force, we simulate all possible scenarios, and stop when from given state we can not reach result.</p>
  
  <pre><code> arr[] = [1,2]
      k = 6
     globalCount =0;
     function findSum(arr,k)
     {
        if(k ==0)
           globalCount++
           return
        else if(k&lt;0)
           return
  
        for each i in arr{
         arr.erase(i)
         tmp = k
         findSum(arr,tmp)
         while(k&gt;=0){
            findSum(arr,tmp -= i)
        } 
     }
  </code></pre>
  
  <p>I am not sure if my solution is most efficient one out there. Please comment /correct or show pointers to better solutions.</p>
  
  <p>EDIT : Would really appreciate if someone can give me runtime complexity of my code and their soln code. :)
  Mine code complexity I think is   Big-O( n^w )    w = k/avg(arr[0]..arr[n-1])</p>