You know how to define states, write transitions, and handle base cases. You have solved Coin Change, grid paths, and maybe even some string DP.
But hand you a NEW problem --- one you have never seen --- and how do you decide if it is DP, greedy, or backtracking? How do you know WHICH kind of DP?
Most people rely on keyword heuristics: “minimize” means DP, “generate all” means backtracking. These heuristics fail on real problems. Let us find out if yours work.
Four problems. No hints. No framework. Just your gut.
Classify each one, see what happens when you are wrong, then build the tool that makes gut instinct unnecessary.
6.Classify this problem:
You discovered it yourself: the state SHAPE reveals the family.
Next time you face a new problem, do not ask “is this DP?” Ask: “what is the state?” The shape will answer everything else.