

Slimes = {10, 7, 3}
On mixing slime 3 and 7 remaining slimes are: {10, 10} and the cost is 3 * 7 = 21.
On mixing slime 10 and 10 remaining slimes are: {10} and the cost of mixing is 10 * 10 = 100.
So the final cost of mixing the slime is 121.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first line of each test case contains a single integer ‘N’ denoting the total number of slimes.
The next line contains 'n' integers denoting the size of the slimes.
For each test case, print a single integer “ans” denoting the minimum cost of converting all these slime into one single slime.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 100
0 <= slime[i] <= 99
Time limit: 1 sec
In this approach, we will start combining every adjacent slime and check for the minimum possible cost.
The steps are as follows:
This approach is similar to the previous approach, the only difference is we are storing the minimum cost for all subarrays and use the precomputed values when required.
The steps are as follows:
In this approach we will take two 2D arrays “dp” and “sum”. “dp[i][j]” will store the minimum cost of combining all the slimes from index i to index j and sum[i][j] will contain the final size of the slime after combining all the slimes from i to j.
The steps are as follows: