How can it be 232 max if it can be 262 and 247?
Andremaxico How did you manage to get such results? Maybe you misunderstood the problem. Here are a few possible outcomes in the example:
Selling first, second, third, then fourth ticket respectively: max(2 - 0, 0) * 37 + max(3 - 1, 0) * 45 + max(1 - 2, 0) * 46 + max(4 - 3, 0) * 30 = 194
Selling fourth, third, second, then first ticket respectively:max(4 - 0, 0) * 30 + max(1 - 1, 0) * 46 + max(3 - 2, 0) * 45 + max(2 - 3, 0) * 37 = 165
Selling second, first, fourth, then third ticket respectively(the maximum possible result):max(3 - 0, 0) * 45 + max(2 - 1, 0) * 37 + max(4 - 2, 0) * 30 + max(1 - 3, 0) * 46 = 232
How can I implement dynamic programming algorithm on this question? There is dynamic programming tag in this question
ilkinimanov You are asking for the answer
The problem is interesting for this part how to make connectivity between numbers and implement it in dynamic programming.