Recurrence relation
for ( int j = 0 ; j < k ; j ++ ) { int x = ( r / exp_c . get ( j ) ) % ( c + 1 ) ; if ( x - w [ i ] >= 0 ) { dp . get ( i ) . set ( r , Math . max ( dp . get ( i ) . get ( r ) , w [ i ] + FindMax ( i + 1 , r - w [ i ] * exp_c . get ( j ) , w , n , c , k ) ) ) ; } }