R
R
Roman Nazarkin2015-09-12 07:11:46
Mathematics
Roman Nazarkin, 2015-09-12 07:11:46

How to decompose a number into a sum of other numbers?

Greetings!
The question is: For example, there is a set of numbers (2, 3, 4, 5, 6) and some arbitrary number such that n >=2. So, you need to decompose this number into the sum of the above (they can be repeated in the original set).
Example: the number 7 can be decomposed as 3 + 4. The number 9 as 5 + 4. The number 11 can be decomposed as 5 + 4 + 2.
Are there such algorithms? Well, an example in any language, if any, is very welcome.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2015-09-12
@gbg

This is called the knapsack packing problem. Further - in Wikipedia.

S
Sergey, 2015-09-12
@zenden2k

Dig into Dynamic Programming
The Subset Sum Problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question