text: Fill the subset table in bottom up manner
code: for ( int i = 1 ; i <= sum ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { subset [ i , j ] = subset [ i , j - 1 ] ; count [ i , j ] = count [ i , j - 1 ] ; if ( i >= set [ j - 1 ] ) { subset [ i , j ] = subset [ i , j ] || subset [ i - set [ j - 1 ] , j - 1 ] ; if ( subset [ i , j ] ) count [ i , j ] = Math . Max ( count [ i , j - 1 ] , count [ i - set [ j - 1 ] , j - 1 ] + 1 ) ; } } } return count [ sum , n ] ; }