title: Interesting variation to the subset sum problem
body: <p>An interesting variation of the subset sum problem was presented to me by a friend from work:</p>
  
  <p>Given a set S of positive integers, of size n, and integers a and K, is there a subset R (of the set S) that contains <strong>exactly a elements</strong>, whose sum is equal to K?</p>
  
  <p>He claims that this can be done with time complexity O(nka), I was unable to come up with a dynamic programming algorithm that achieved this running time. Can it be done?</p>