P
P
pcdesign2015-02-13 20:13:32
Python
pcdesign, 2015-02-13 20:13:32

How to adjust the result having a list of numbers and a total sum?

There is a list of some number of digits.
For example:
[1, 2, 7, 9]
And there is a final amount that should be obtained.
For example, the total sum is 51.
Purpose: use the maximum possible number of digits from the list
and multiply the maximum possible number of digits.
Something like this:
1*2 + 2*4 + 7*2 + 9*3 = 51
How can I make the program output 1*2 + 2*4 + 7*2 + 9*3?
At the input I received a list of numbers and the total amount to be received.
And gave back the expression.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2015-02-13
@pcdesign

The standard knapsack packing problem. On such a small scale, it is solved by direct enumeration.

M
Mrrl, 2015-02-13
@Mrl

Wouldn't 1*33+2*1+7*1+9*1=51 be better in this example? All figures are involved, and in the maximum possible quantity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question