Can any help me give a solution using top down (memo + recursion) technique,for some reason my solution isn't counting all the possible answers,please help me as i'm new to dp. http://mirror.codeforces.com/problemset/problem/163/A http://ideone.com/AEMNUw









Your rec(i, 0) actually counts only such pairs where x starts at position i. You never increase i unless s[i] == s[j];. res += rec(i, 0) for all i < s.size();