Блог пользователя 444iq

Автор 444iq, история, 5 лет назад, По-английски

How to approach this problem. My approach was to find the prfix from 0 to i and suffix from n — 1 to i + 1. concatenate both for a new string and find longest palindromic subsequence for the current string. But it gave wrong answer and later I realized that my approach will not work always.

Any other approach for this problem. The tag was dp for the problem.

Thanks.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

I think it can be easily solved in O(|S|^3). Break S into two parts and find longest common subsequence b/w two parts. Answer will be maximum among all cases.

There are |S| ways to break and LCS can be solved in |S|^2.

Giving a complexity of n^3.