The problem is that i can use multiple times the values from the array (i can only add them ) . I need to find what is the minimum values used from that array to get the m number.
Like
7 10000
12 1 11 30 14 2 18
A brute force approach would be a recursive function. Take the example from your last message:
7 10000
12 1 11 30 14 2 18
Start with a target sum of 10,000.
For each multiple i of 12 from 0 to 10,000/12:
target sum = 10,000-12i
make a recursive call with the new target sum, and working with the next number (1 in this case).
I've left a lot of the details out, but hopefully you get the idea.