Stores the values of overlapping subproblems
var dp = Array . from ( Array ( M ) , ( ) => Array ( M ) ) ; for ( var i = 0 ; i < M ; i ++ ) for ( var j = 0 ; j < M ; j ++ ) dp [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; document . write ( countNum ( N , 0 , K , 0 , dp ) ) ;