


You have an infinite number of umbrellas of each type.
If it is not possible to shelter exactly ‘M’ people then print -1.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains two space-separated integers ‘N’ denoting the number of elements in the array “UMBRELLA” and ‘M’ denoting the number of people required to cover with umbrellas.
The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array “UMBRELLA”.
For each test case, print the minimum number of required umbrellas.
Print the output of each test case on a new line.
You don’t need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^3
1 <= UMBRELLA[i] <= 10^9
1 <= M <= 10^3
Where ‘T’ represents the number of test cases, ‘N’ represents the number of types of umbrellas, “UMBRELLA[i]” represents the number of people it can cover, and ‘M’ denotes the number of people to cover with umbrellas.
Time Limit: 1 sec
Approach: The idea here is to try every possible option and consider the minimum ans.
We have two possible options: either we use the i-th umbrella to cover people or not.
So, the recurrence for the above problem is:
minNumberOfUmbrellas(i, M) represents the minimum number of umbrellas required to shelter M people with first i umbrellas.
If we skip the i-th umbrella then the sub-problem is the same as solving for minNumberOfUmbrellas(i - 1, M) - a minimum number of umbrellas required to shelter M people with the first i - 1 umbrella.
If we consider the i-th umbrella then the sub-problem is the same as solving for 1 + minNumberOfUmbrellas(i, M - UMBRELLA[i]) - a minimum number of umbrellas required to shelter M - UMBRELLA[i] people with first i umbrellas (since we have an infinite umbrella of i-th type). Since we are considering the i-th umbrella we add 1 to the sub-problem.
The algorithm is as follows:
Approach: In the previous approach, there will be a lot of overlapping subproblems. Hence, we can store results of subproblems by applying memoization to the previous approach and optimize it.
The algorithm is as follows:
Approach: The idea is to use dynamic programming to store the results of a subproblem and then use the stored results to solve other subproblems.
The algorithm is as follows: