Now I write the DP formally using the prefix idea.
Define the state Let = can you split the prefix into valid blocks? This is a boolean state.
Set the base case The empty prefix is always valid, so All other values start as false: Now that you have your state definition and base case ready, the next step is to build the transition (how to compute dp[i] from earlier values). Without this stopping condition, the recursion would never terminate.