Input: n (number of values in array)

m (value u need to fill with the values from array)

4 100

40 50 10 30

OUTPUT

2

(50+50=100) (2 - Solution problem)

(40+50+10=100)(3)

Any tips how to solve this?

m (value u need to fill with the values from array)

4 100

40 50 10 30

OUTPUT

2

(50+50=100) (2 - Solution problem)

(40+50+10=100)(3)

Any tips how to solve this?

Last edited on

Try all the permutations and combinations of values and operations (+, -, *, /), then print the values that match.

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

Output:

335

Like

7 10000

12 1 11 30 14 2 18

Output:

335

This sounds like projecteuler.net problem :)

A brute force approach would be a recursive function. Take the example from your last message:

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.

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.

Topic archived. No new replies allowed.