1. Preprocessing
Fill palindrome table by length; each check O(1) using inner substring.
for len in 1..n:
for i in 0..n-len:
j = i+len-1
if s[i]==s[j] and (len<=2 or pal[i+1][j-1]):
pal[i][j] = True
Exploring palindrome preprocessing and minimum cut transitions.
dp[i] cuts
pal[i][j] bool
min over j
Fill palindrome table by length; each check O(1) using inner substring.
for len in 1..n:
for i in 0..n-len:
j = i+len-1
if s[i]==s[j] and (len<=2 or pal[i+1][j-1]):
pal[i][j] = True
if pal[0][i]:
dp[i] = 0
else:
dp[i] = min(dp[j] + 1) for 0<=j<i if pal[j+1][i]