V
V
Vladimir Ionenko2016-11-11 14:52:37
Programming
Vladimir Ionenko, 2016-11-11 14:52:37

What method is used to solve this problem?

Good afternoon, please tell me how to solve this problem. What solution algorithm is needed to complete the task. Am I interested in the logic itself? Thanks in advance.
Task:
Candies weigh X grams, tangerines - Y grams and an apple - Z grams.
You need to write a program that will determine how many different options for gifts weighing exactly W grams Santa Claus can make.
Input
The function must receive four integers X, Y, Z and W.
Output
The function must return one integer - the number of gift options.
Example:
X = 10
Y = 25
Z = 15
W = 40
Result: 3

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2016-11-11
@Stalker_RED

This is a special case of the knapsack problem , which occurs in almost every second textbook.

I
Ivan, 2016-11-11
@LiguidCool

Hmm... At first glance.
1) Select the heaviest, medium and light. For example XYZ respectively.
2) W is divided by the heaviest, X.
3) The remainder of point 2 is divided by Y.
4) The remainder of 3 is divided by Z.
Then you essentially repeat these points. Those. it's a cycle.
5) Divide W by X again. But add the weight of ANOTHER X to the remainder.
6) Add 2-5 until it stops dividing.
I think it's clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question