Recursive function is very powerful. Here's my short MATLAB code. rsum
================================================================
function c = rsum(v,m,c)
for i=1:length(v)-1,if v(i)<=m,c=rsum(v(i:end),m-v(i),c);end,end
c = c+1;
================================================================
Then, call this function in MATLAB
c = rsum([25 10 5 1],37,0)
you will get c = 24 for your problem.
More interestingly, if you make the following call
c = rsum([100,50,25,10,5,1],100,0)
you will get the answer for the classical question: How many ways to make
change for a dollar. (c = 293 in this case). You can google "How many ways
to make change for a dollar" to verify the answer.