Traverse through every digit and recursively count numbers beginning with it
for ( $ i = 0 ; $ i < 10 ; $ i ++ ) if ( $ sum - $ i >= 0 ) $ ans += countRec ( $ n - 1 , $ sum - $ i ) ; return $ lookup [ $ n ] [ $ sum ] = $ ans ; }