# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916284 | vjudge1 | Palindromic Partitions (CEOI17_palindromic) | Cpython 2 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
def is_palindrome(s):
return s == s[::-1]
def max_palindromic_partition(s):
n = len(s)
dp = [0] * n
for i in range(n):
max_partition = 0
for j in range(i+1):
if is_palindrome(s[j:i+1]):
max_partition = max(max_partition, 1 + (dp[j-1] if j > 0 else 0))
dp[i] = max_partition
return dp[n-1]
# Input
t = int(input())
for _ in range(t):
s = input().strip()
# Output
print(max_palindromic_partition(s)))