What method to solve this problem?

Good afternoon, prompt please how to solve this problem. What's the solution algorithm required to perform the task. I'm interested in the logic? Thanks in advance.

Task:

Candy weigh X grams, tangerine - Y grams and the Apple - Z grams.
Need to write a program that will determine how many different options of gifts weight exactly W grams can make Santa Claus.
Input
The function should have four integers X, Y, Z and W.
Output
The function should return a single integer - the number of gift options.
Example:
X = 10
Y = 25
Z = 15
W = 40
Result: 3
July 2nd 19 at 17:43
2 answers
July 2nd 19 at 17:45
This is a special case of the knapsack problem, which is almost every second tutorial is found.
July 2nd 19 at 17:47
Hmm ... At first glance.
1) choose the heavy , medium and light. For example, XYZ respectively.
2) W is divided into the heaviest , X.
3) the Remainder of paragraph 2 is divided by Y.
4) the Remainder when 3 is Divided by Z.
Then you essentially repeat these points. Ie this cycle.
5) re-divide W into X. But to the remainder add the weight of ANOTHER X.
6) Upholstery 2-5 until the shares cease.
I think more clearly.

Find more questions by tags Programming