Statistics

Problem Statement for "PalindromicSubsequences"

Problem Statement

A palindrome is a sequence that can be read the same forwards and backwards. For example, ABBA and ABCBA are palindromes, while ABCAB and ACAB are not.

Given a String s, how many ways can a subsequence of letters be taken such that it forms a palindrome? Since this number may be large, return the value MOD 10000019.

Definition

Class:
PalindromicSubsequences
Method:
count
Parameters:
String
Returns:
int
Method signature:
int count(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 100 upper-case ('A'-'Z') characters.

Examples

  1. "AB"

    Returns: 2

    The best we can do here is to take either single letter as a palindrome.

  2. "ABA"

    Returns: 5

    We can take any single letter, the pair AA, or the whole string ABA, a total of 5 possibilities.

  3. "AAA"

    Returns: 7

    Any non-empty subsequence is a palindrome.

  4. "ABCBA"

    Returns: 13

  5. "ABCDEFGHABC"

    Returns: 35

  6. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

    Returns: 5322941

  7. "ABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXYABCDEFGHIJKLMNOPQRSTUVWXY"

    Returns: 456975

  8. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    Returns: 26

  9. "ABCDEFGHIJKLMNABCDEFGHIJKLMNABCDEFGHIJKLMNOPQRSTUVWXYOPQRSTUVWXYOPQRSTUVWXY"

    Returns: 5101

  10. "ABCABCDEFGHIJKLMNOPQRSTUVWDEFGHIJKLMNOPABCDEFGHIJKLMNOPQRSTUVWQRSTUVW"

    Returns: 15289

  11. "ABCDEFAAAAAAGHIJBBBBBCCCCCBBLMNOPQRSTUVW"

    Returns: 3405

  12. "BDCACBCACDBADBADCABDCBDDBABBABCBDBDBBABBDDBAADDBABADCDCD"

    Returns: 1943036

  13. "AAABBBBBAABABBAAAABBAAAABAABBAABBAB"

    Returns: 9081146

  14. "WNUXUNXWUNUNUUWXNUXNWUNUXWNUXUNXWUNUNUUWXNUXNWUNUXWNUXUNXWUNUNUUWXNUXNWUNUXWNUXUNXWUNUNUUWXNUXNWUNUX"

    Returns: 931383


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: