The key for dp is to find the variables to represent the states and deduce the transition function. (aka find state > find relation > find constraints)
Take Best Time to Buy and Sell Stock with Cooldown as an example:
Find state
The natural states for this problem is the 3 possible transactions : buy, sell, rest.
Because the transaction sequences can end with any of these three states. For each of them we make an array, buy[n], sell[n] and rest[n]., which represents the maxProfit for any sequence end with buy/sell/rest.
Find relation
Then we want to deduce the transition functions for buy sell and rest. By definition we have:
 buy[i] = max(rest[i1]price, buy[i1])
 sell[i] = max(buy[i1]+price, sell[i1])
 rest[i] = max(sell[i1], buy[i1], rest[i1])
Where price is the price of day i. All of these are very straightforward. They simply represents :  We have to
rest
before webuy
and  we have to
buy
before wesell
Find constraints
One tricky point is how do you make sure you sell before you buy, since from the equations it seems that [buy, rest, buy] is entirely possible.
Well, the answer lies within the fact that buy[i] <= rest[i] which means rest[i] = max(sell[i1], rest[i1]). That made sure [buy, rest, buy] is never occurred.
A further observation is that and rest[i] <= sell[i] is also true therefore
rest[i] = sell[i1]
Substitute this in to buy[i] we now have 2 functions instead of 3:buy[i] = max(sell[i2]price, buy[i1])
 sell[i] = max(buy[i1]+price, sell[i1])
This is better than 3, but, we can do even better
Since states of day i relies only on i1 and i2 we can reduce the O(n) space to O(1). And here we are at our final solution:
1 
