knapsack-problem

How to solve this question asked in premium coding contest?

不打扰是莪最后的温柔 提交于 2020-08-19 05:49:48
问题 Could someone guide me on how to solve this programming question? It seems something like DP problem which I couldn't find answer for. Question: There are ‘n’ ads. Each ad has an effectiveness value associated with it which is given in an array of size ‘n’ in the format [v1, v2, …, vn], where ‘v1’ is the effectiveness value of the first ad, ‘v2’ is the effectiveness value of the second ad, and so on. The show in which these ads will be shown is ‘m’ length long (starting from 0 till m), and

Binpacking — multiple constraints: weight+volume

不羁的心 提交于 2020-08-01 09:08:06
问题 I have a dataset with 50,000 orders. Each order has ~20 products. Product volume and weight are present (as well as x,y,z dimensions). I have shipping boxes of constant volume V_max and maximum weight capacity of W_max. Per order I want to minimize the number of boxes used under the constraint that V < V_max, and W < W_max. In searching the web I have come across many binpacking algorithms, but none of them seem to do the trick. Does anyone know of an elegant (and fast) python algorithm for

0/1 knapsack with dependent item weight?

时光毁灭记忆、已成空白 提交于 2020-07-28 07:01:18
问题 The standard 0/1 knapsack requires that the weight of every item is independent to others. Then DP is a efficient algorithm towards the solution. But now I met a similar but extensions of this problem, that the weight of new items are dependent on previous items already in the knapsack. For example , we have 5 items a , b , c , d and e with weight w_a , ..., w_e . item b and c have weight dependency. When b is already in the knapsack, the weight of item c will be smaller than w_c because it

Optimization problem - How to add same team constraint

北城余情 提交于 2020-06-29 04:34:39
问题 How the dataset looks like: I'm trying to build an optimization tool for fantasy football, but I'm having difficulty forcing the model to use players from the same team. 9 players form a lineup, need to be under 50k and we are maximizing "proj" projected points self.salary_cap = 50000 self.Minsalary_cap = 0 self.header = ['QB', 'RB', 'RB','WR', 'WR', 'WR', 'TE','FLEX', 'Def'] #define the pulp object problem prob = pulp.LpProblem('NFL', pulp.LpMaximize) #define the player variabless players

Knapsack with limit on total items used

不羁岁月 提交于 2020-06-25 05:46:28
问题 So, I have a knapsack where a number of items that can be placed into the knapsack has a limit, while the amount of weight of the items also has a limit. So given item limit 5, and weight 100: We would find the 5 items (can repeat 5x same item) that best fit weight 100. I have solved both unbounded and bounded(each item has a limit, but the total amount of items used has no limit) in dynamic programming. But I'm a bit confused with how to do this new approach. Would this be a multidimensional

Given a collection of integers and threshold value T, divide the collection into as many groups as possible whose sum >= T

安稳与你 提交于 2020-05-12 07:56:07
问题 Given a collection of integers and threshold value T, divide the collection into as many groups as possible whose sum >= T. The remaining integers (whose sum < T, so another group cannot be formed) should be left outside of the groups. Constraints: length of the list <= 1,000 values and T <= 1,000,000 Is there an algorithm for this problem in polynomial time? For example given [25,25,25,50,50,50,10] and a threshold T = 70 it should return: [25,50] [25,50] [25,50] Remaining: [10] Selecting [25

How do I sort the possibilities vector in 0/1 knapsack problem using the template min_max function I have written?

大城市里の小女人 提交于 2020-04-16 05:47:23
问题 SO already has multiple questions related to this topic. My question ain't 'bout the algorithm. It's 'bout sorting the final possibilities vector as per profit I wrote the following piece of code to solve the 0/1 knapsack problem: #include "algorithms.h" struct Item { int index = 1; int profit = 1; int weight = 1; Item() = delete; explicit Item(int i, int _profit, int w) { index = i; profit = _profit; weight = w; } bool operator<(const Item& item) { return this->profit < item.profit; } bool

Finding the minimum number of values in a list to sum to value

老子叫甜甜 提交于 2020-03-05 10:40:29
问题 So if I was given a sorted list/array i.e. [1,6,8,15,40], the size of the array, and the requested number.. How would you find the minimum number of values required from that list to sum to the requested number? For example given the array [1,6,8,15,40], I requested the number 23, it would take 2 values from the list (8 and 15) to equal 23. The function would then return 2 (# of values). Furthermore, there are an unlimited number of 1s in the array (so you the function will always return a

Knapsack 0-1 with fixed quanitity

别来无恙 提交于 2020-02-24 05:45:08
问题 I'm writing a variation of knapsack 0-1 with multiple constraints. In addition to a weight constraint I also have a quantity constraint, but in this case I want to solve the knapsack problem given that I'm required to have exactly n items in my knapsack, with a weight less than or equal to W. I'm currently implementing a dynamic programming ruby solution for the simple 0-1 case based off of the code at Rosetta Code at http://rosettacode.org/wiki/Knapsack_problem/0-1#Ruby. What's the best way