CHRL4 beginners

Can anyone send and explain me this problem in beginners category

It’s not exactly easy, but the main logic is instead of storing the answer, store the log of the answer in a long double. then it’s a dp sum of minimising the sum. To do that, I used a set to store all the values that I can come here from.
commented code
https://www.codechef.com/viewsolution/30547100
Please link the question in the post from next time.