← 返回 bytedance 的题目列表Count Different Palindromic Subsequences
类型:online_judge
Given a string s, return the number of distinct palindromic subsequences in s. Two subsequences are considered different if their resulting strings are different (regardless of chosen indices).
Note: This is a hard DP problem that requires careful deduplication to avoid over-counting.
Example
Input: "bccb"
Output: 6
Distinct palindromic subsequences include: "b", "c", "bb", "cc", "bcb", "bccb"
Constraints
1 <= len(s) <= 1000
s consists of lowercase letters
The answer can be large; apply modulo if required by the interviewer.
Example
Input
bccb
Output
6