Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

COUNTPAL - Editorial

$
0
0

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

The problem can be solved easily by dynamic programming:

F(i) = CountPal(s') for s' is the subtring of s[1]..s[i]

so F(i) = sum of F(j) with j < i whether the substring of s[j+1]..s[i] is a palindrome.

To verify a substring is a palindrome or not, we can pre-compute to save time of DP.

Complexity: O(|s|^2)


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>