打印给定字符串中的所有回文子序列不明显

问题描述

GFG 上有很多此类问题,例如计算给定字符串中的所有回文子序列。但我在任何地方都没有发现这个问题:

Print all Palindromic Subsequences in a given string (not distinct).

我查看了 GFG 上的 this article 并尝试测试它的字符串“aba”以供理解,我发现 ans 为 5,但据我所知,可能的回文子序列是 {'a','b','a','aa'} and they are 4。>

So my question is why it is 5 and what is the fifth palindromic subsequence in "aba" that I am not able to find? 

因此,我无法理解在给定字符串中计算所有回文子序列的问题。请帮忙!

解决方法

既然 aba 已经是一个回文,它必须包含在所有回文子序列的集合中。

所以最终答案是:{'a','b','a','aa','aba'}