1156. Maximize the Cut Segments

EasyDynamic ProgrammingUnbounded KS

Given a rod of length n and three allowed cut lengths x, y, and z, cut the rod into the maximum number of pieces where every piece has length x, y, or z. Return that maximum count, or 0 if the rod cannot be exactly cut. The input is JSON {n, x, y, z}.

Input: JSON {n, x, y, z}.

Output: Integer — the maximum number of segments.

Examples

Example 1
Input: {"n":5,"x":5,"y":3,"z":2}
Output: 2
Explanation: Cut into 3 and 2.
Example 2
Input: {"n":4,"x":2,"y":1,"z":1}
Output: 4
Explanation: Four pieces of length 1.
Example 3
Input: {"n":3,"x":2,"y":2,"z":2}
Output: 0
Explanation: Cannot cut exactly.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →