hello
I need help to find the count of the number of palindromic subsequences in the given string since this question is an extension of the longest palindromic subsequence
//my code for longest palindromic subsequence
int longestPalindromeSubseq(string s) {
int n=s.size();
vector<vector<int>> dp(n+1,vector<int>(n+1,0));
string rev=s;
reverse(rev.begin(),rev.end());
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(s[i-1]==rev[j-1])
{
dp[i][j]=dp[i-1][j-1]+1;
}
else
{
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
}
return dp[n][n];
}
Given a string str of length N, you have to find number of palindromic subsequence (need not necessarily be distinct) which could be formed from the string str.
Input:
Str = "aab"
Output:
4
Explanation:
palindromic subsequence are :"a", "a", "b", "aa"
if you can suggest any approach from above code it would a great help