Store palindromes of size 2
for ( i = 0 ; i < s . Length - 1 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { dp [ i , i + 1 ] = 1 ; if ( ! m . ContainsKey ( s . Substring ( i , 2 ) ) ) m . Add ( s . Substring ( i , 2 ) , true ) ; }