Initialize dp table
let table = new Array ( n + 1 ) ; for ( var i = 0 ; i < table . length ; i ++ ) { table [ i ] = new Array ( 2 ) ; } for ( var i = 0 ; i < table . length ; i ++ ) { for ( var j = 0 ; j < table . length ; j ++ ) { table [ i ] [ j ] = 0 ; } } for ( let i = 1 ; i <= x ; i ++ ) { table [ 0 ] [ i ] = Number . MAX_VALUE - 1 ; }