Else value is obtained considering two cases . a ) All substrings without last character in S b ) All substrings without last characters in both .
else $ mat [ $ i ] [ $ j ] = $ mat [ $ i ] [ $ j - 1 ] + $ mat [ $ i - 1 ] [ $ j - 1 ] ; } }