initialize the dp table and set all values to 0 pref [ i ] [ j ] will contain min ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] , ... dp [ i ] [ j ] )
var dp = new Array ( N , MAX ) ; var pref = new Array ( N , MAX ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = 0 ; pref [ i , j ] = 0 ; } }