


Output the sum modulo 10 ^ 9 + 7.
If βXβ = 1, βYβ = 1 and βZβ = 0 then the output will be 84.
Explanation : 3 + 4 + 34 + 43 = 84
The first line contains an integer βTβ which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first and only line of each test case contains three space-separated integers denoting βXβ, βYβ, and βZβ respectively.
For each test case, print a single line containing the sum of all the numbers formed by having 3 at most βXβ times, having 4 at most βYβ times, and having 5 at most βZβ times as a digit.
The output of each test case will be printed in a separate line.
You donβt need to print anything; It has already been taken care of. Just implement the given function.
1 <= T <= 50
0 <= X, Y, Z <= 10
Where βTβ is the number of test cases and βXβ, βYβ and βZβ are the three integers.
Time limit: 1 sec.
The basic idea is to make all possible combinations of numbers having βXβ 3s, βYβ 4s and βZβ 5s as digits and adding them to get the desired result.
In this approach we will be using Dynamic programming. We will find all combinations of numbers having exactly X - 3βs, Y - 4βs and Z - 5βs, and then add them to get our desired sum.
For this, we will create two 3D-DP arrays, letβs say βnum[N][N][N]β, βsum[N][N][N]β, where βNβ is the maximum possible value of βXβ, βYβ and βZβ:
sum[i][j][k] = 10 * (sum[i - 1][j][k] + sum[i][j - 1][k] + sum[i][j][k - 1])
+ 3 * num[i - 1][j][k]
+ 4 * num[i][j - 1][k]
+ 5 * num[i][j][k - 1]
Count of Subsequences with Given Sum
Optimal Line Arrangement
Distinct Integers After Zero Removal
Maximize Partition Value
Maximum Value Path in a Graph