For the less difficult ones of these problems, they may have an "optimal substructure", e.g. "f(inputs)[k] = max{ operation(f(inputs)[j]) | j <= k-1 }", to exploit and we can just iterate K times to get the answer.
- p188_Best_Time_to_Buy_and_Sell_Stock_IV
- p787_Cheapest_Flights_Within_K_Stops
- p1531_String_Compression_II
- p1751_Maximum_Number_of_Events_That_Can_Be_Attended_II
For the more difficult ones of these problems, they often don't have an "optimal substructure", or exploiting the "optimal substructure" isn't fast enough, hence demanding us to derive a "greedy step for current state".
For some peculiar ones where K is very small but neither an "optimal substructure" nor an obvious "greedy step for current state" is available, we can just search exhaustively.