Approach
We will solve two parts separately. First lets find the min number of moves.
Let n
be the size of s and m
be the size of t.
Minimum number of moves.
Let ans[l][r]
denote minimum number of moves to delete all occurrence of t in s[l]...s[r]
.
1. if there is no index j
, in [l,r]
such that j+m-1 < r
and s[j...j+m-1] == t
then ans[l][r] = 0
.
2. else for all j
's described above ans[l][r] = min(ans[l][r], ans[l][j-1] + 1 + ans[j+m][r])
The minimum number of moves are ans[0][n-1]
.