Looks like an easy dynamic programming task.
Suppose that there are N elements in array A, and you want to get the minimum number of elements whose sum is S. Then we can easily solve the problem with time complexity O (N x S).
Consider dp [i] [j] - the minimum number of elements among the first elements i, the sum of which is j, 1 <= i <= N and 0 <= j <= S. Then for A [i] <= j <= S :
dp [i] [j] = min (, dp [i - 1, j], 1 + dp [i - 1] [j - A [i]]).
, dp [0] [0] = 0, dp [0] [j] = 0 < j <= S.