Update dp [ ] [ ] on the basis recurrence relation
if ( j == 0 ) { dp [ i ] [ j ] = ( str [ j ] == currentChar ) ? 1 : 0 ; } else { dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + ( ( str [ j ] == currentChar ) ? 1 : 0 ) ; } } }