title: Count Palindromic Subsequence Given String
signature: pub fn count_palindromic_subsequence_given_string(str: String) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(str: String, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(str), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "R".to_string(), 
        1
      ));
      
      println!("TEST-1...{}", driver(
        "2956350".to_string(), 
        10
      ));
      
      println!("TEST-2...{}", driver(
        "11100111110101".to_string(), 
        2798
      ));
      
      println!("TEST-3...{}", driver(
        "TZTDLIIfAD".to_string(), 
        20
      ));
      
      println!("TEST-4...{}", driver(
        "98".to_string(), 
        2
      ));
      
      println!("TEST-5...{}", driver(
        "1100100001".to_string(), 
        270
      ));
      
      println!("TEST-6...{}", driver(
        "oKwGeatf".to_string(), 
        8
      ));
      
      println!("TEST-7...{}", driver(
        "19".to_string(), 
        2
      ));
      
      println!("TEST-8...{}", driver(
        "00010110100".to_string(), 
        563
      ));
      
      println!("TEST-9...{}", driver(
        "Cyq".to_string(), 
        3
      ));
      
  }
source_py: def count_palindromic_subsequence_given_string(str):
      N = len(str)
      cps = [[0 for i in range((N + 2))] for j in range((N + 2))]
      for i in range(N):
          cps[i][i] = 1
      for L in range(2, (N + 1)):
          for i in range(N):
              k = ((L + i) - 1)
              if (k < N):
                  if (str[i] == str[k]):
                      cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) + 1)
                  else:
                      cps[i][k] = ((cps[i][(k - 1)] + cps[(i + 1)][k]) - cps[(i + 1)][(k - 1)])
      return cps[0][(N - 1)]
source_cpp: int count_palindromic_subsequence_given_string(string str) {
    int N = str . length ( );
    int cps [ N + 1 ] [ N + 1 ];
    memset ( cps, 0, sizeof ( cps ) );
    for ( int i = 0;
    i < N;
    i ++ ) cps [ i ] [ i ] = 1;
    for ( int L = 2;
    L <= N;
    L ++ ) {
      for ( int i = 0;
      i < N;
      i ++ ) {
        int k = L + i - 1;
        if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1;
        else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ];
      }
    }
    return cps [ 0 ] [ N - 1 ];
  }