Consider a game in which players can choose any of the three coins => 3 or 5 or 10 in a move. There is an infinite supply of all the three types of coins. Given a total amount βNβ, find the distinct combinations which sums up to 'N'.
Note :3,5 and 5,3 are not distinct combinations.
Input format:
The first line of input contains an integer βTβ denoting the number of test cases.
The first and only line of each test case contains an integer βNβ , the total amount.
Output format:
For each test case, return the number of distinct combinations to reach the total amount is printed.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5 * 10^4
Time Limit: 1 sec
1
8
1
{3,5} and {5,3} are two possible permutations but these represent the same combination. Thus, the output is 1.
2
20
13
4
2
For test case 1 : N = 20
Possible distinct combinations are :
3 3 3 3 3 5
5 5 5 5
5 5 10
10 10
For test case 2 : N = 13
Possible distinct combinations are :
3 5 5
3 10
Think of trying all possible combinations.
To count all possible distinct combinations to reach the total amount of βNβ using coins of 3,5 and 10, we can divide all solutions in two sets.
The total number of distinct combinations can be found using recursion.
Algorithm:
O(2^N) where βNβ is the total amount.
Using every coin we are finding the count of distinct combinations for almost all the values from 0 to βNβ. This takes exponential time, that is β2 ^ Nβ. Thus, the total time complexity is O(2 ^ N).
O(N), where βNβ is the total amount.
We are using recursion. So O(N) space will be taken by the recursion stack. Thus the final space complexity is O(N).