Problems > Fewest Palindrome Cuts

Fewest Palindrome Cuts

Difficulty: 1900 5000 ms 128 MB

strings dp

Split S into the minimum number of contiguous pieces, each a palindrome. Print the minimum number of CUTS (pieces − 1).

Input: one line with the string S.

Output: the minimum number of cuts.

Constraints:

  • 1 ≤ |S| ≤ 2000
  • lowercase letters

Sample Tests

Input 1
aab
Output 1
1
Input 2
abc
Output 2
2

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.