def knapsack_rep(weights, values, W):
 k = ([0] * (W + 1))
 for w in range(1, (W + 1)):
  k[w] = max([((k[(w - i)] + values[i]) if (weights[i] <= w) else 0) for i in range(len(weights))])
 return k[(-1)]

def knapsack_rep ( weights , values , W ) : k = ( [ 0 ] * ( W + 1 ) ) for w in range ( 1 , ( W + 1 ) ) : k [ w ] = max ( [ ( ( k [ ( w - i ) ] + values [ i ] ) if ( weights [ i ] <= w ) else 0 ) for i in range ( len ( weights ) ) ] ) return k [ ( - 1 ) ]
knapsack with repetition .