Define = minimum operations to convert the first characters of A into the first characters of . The answer is .
This "prefix to prefix" pattern (comparing beginnings of both strings) is the foundation of all string DP. The state must capture everything needed to solve the subproblem. If you are missing information, you cannot compute the answer correctly. If you include too much, your solution will be slow or use too much memory.