Count of palindromes of length N having atmost k distinct characters such that no prefix (of size 2 to n-1) is palindrome

Правка en2, от lsr10122018, 2019-09-24 16:37:44

Count of palindromes of length N having atmost k distinct characters such that no prefix (of size 2 to n-1) is palindrome.

for example If N = 3 and K = 3, possible palindromes are "aba", "aca", "bab", "bcb", "cac" and "cbc". so count is 6.

Here is a link of problem and solution https://www.hackerearth.com/problem/algorithm/avoid-prefix-palindromes-cdd47bd7-780d0bca/editorial/

Can anyone help me with this problem?.

Not able to understand the solution mentioned on hackerearth as there is no editorial there. Having difficult time understanding how states are defined in solution.

Теги #dynamic programing, #palindrome, #arrays, #algorithms

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский lsr10122018 2019-09-24 16:37:44 10
en1 Английский lsr10122018 2019-09-24 11:51:18 721 Initial revision (published)