zero bug at DP

first i made detailed analysis of this problem and used a stack to store all the possible states, but it seems hard to be the correct answer. So i used DP instead, and it was accepted at the first submission