I have tried to solve the problem. But , was unsuccessful.
My approach so far :
- Store all the combinations in a temporary 2D array.
- Visit one by one cell of the matrix and update the current cell and adjacent cell.
- Then storing the value of matrix given by the equation in an auxiliary array , which takes O(n^2)
- Now , comparing the results.
This is giving me , TLE. I am not able to come up with overlapping subproblems here.
Can you please help me ?