
If the length of the Golden Rod i.e "LEN" is 5 and "scaleA" is 1, "scaleB" is 2, and "scaleC" is 3; then the different ways to cut Golden Rod into segments are:
Five segments each of length 1 i.e [1, 1, 1, 1, 1].
One segment of length 2 and three segments each of length 1 i.e. [2, 1, 1, 1].
One segment of length 1 and two segments each of length 2 i.e. [1, 2, 2].
One segment of length 3 and two segments each of length 1 i.e. [3, 1, 1].
One segment of length 3 and one segment of length 2 i.e. [3, 2].
If it is not possible to divide the whole Golden rod into segments then return 0.
The first line of input contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains a single integer "LEN" denoting the Length of the Golden Rod.
The second line of each test case contains 3 single space-separated integer "scaleA", "scaleB," and "scaleC", repsectivley.
Print the maximum number of segments the Golden Rod can be cut into.
Print the output of each test case in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= "LEN" <= 10000
1 <= "scaleA", "scaleB", "scaleC" <= 10000
Time Limit: 1 second
The idea is to use recursion to reduce the big problem into several small subproblems. For finding the maximum number of segments that the given length can be cut into, we find the number of segments that can be obtained from shorter lengths i.e ‘LEN - scaleA‘ , ‘LEN - scaleB‘ , ‘LEN - scaleC‘. The required answer would be 1 + max( LEN - scaleA, LEN - scaleB, LEN - scaleC ) as one more cut should be needed after this to cut length ‘LEN'.
If we draw the recursion tree for the recurrence relation of Approach 1, we can observe that there are a lot of overlapping subproblems.

Since the problem has overlapping subproblems, we can solve it more efficiently using memoization by taking an extra ‘memo’ array of size LEN + 1 to store previously calculated results.
The algorithm is similar to the previous approach with some additions.
We initialize a memo[LEN +1] array with -1. memo[i] will store the maximum number of Golden Rod segments that can be made.
Before calling the function for any valid length ‘i’, we will check whether we already have a solution corresponding to that length present in the ‘memo’.
Initially, we were breaking the large problem into small subproblems but now, let us look at it differently. The idea is to solve the small problem first and then reach the final answer. Thus we will be using a bottom-up approach now.