If dynamic programming is used to obtain some optimum solution for a problem. How do you reconstruct the actual steps that lead to that solution?
For example, in the 0-1 knapsack problem you use the recurrence

Using this we can get the maximum value that can be present in the knapsack. How do you find the actual items present.
Can this be generalized for any dynamic programming solution. For eg. To find the actual nos that are part of the longest increasing subsequence whose solution has been obtained using dynamic programming.
No, you can’t in general find the actual solution by inspecting the final values in the DP-table.
If the algorithm simply looks for some optimum value, it will typically discard information regarding how each value was computed.
In a DP-solution the cell on row R could for instance depend on the maximum value in row R-1. Unless the algorithm records which cell was chosen, it will not be possible to reconstruct the actual solution based on the resulting table.
You should however always be able to attach additional information to each cell describing where the value comes from, for instance by references to previously computed cells which the current cell depends upon, and use this information to reconstruct the actual solution.