knapsack-problem

Detecting gaps in grid of divs

亡梦爱人 提交于 2019-12-10 09:42:27
问题 EDIT The solution has been found! Here's a blog post about it, and here is the Github repo! I am working on creating a grid of divs that is composed of multiple sized boxes, these sizes are set height's and widths - but are generated dynamically so each time the page is loaded there is a different grid. My problem - I tried using Masonry, but it winds up leaving gaps, also tried isotope. I am currently floating the elements left which is causing for the breaks in the layout. How it's built -

Dynamic T-SQL approach for combinatorics/knapsack

不问归期 提交于 2019-12-09 06:37:42
问题 I guess my question has to do with a variant of the knapsack problem, but I can't really come up with a solution for this: Let's say you are in a hardware store and need to buy 21 screws. They only offer them in bags: Bag X - 16 Screws - 1.56$ per screw - 25$ Total Bag Y - 8 Screws - 2.25$ per screw - 18$ Total Bag Z - 4 Screws - 1.75$ per screw - 7$ Total Now you have to figure out which Bags you should buy to get your 21 screws (or more!) for the lowest possible price. So what I got is a

Continuous Knapsack Vs. 0-1 Knapsack

旧街凉风 提交于 2019-12-08 13:54:19
问题 Why does Greedy approach work on continuous knapsack problem whereas the same approach does not work for the 0-1 knapsack problem? 回答1: For continuous knapsack, you can't have q > 0 of an item with the cost c per unit in an optimal solution, while leaving q' > 0 of an another item with the cost c' > c . Otherwise, you simply replace min(q, q') amount of the first item with the same amount of the second, increasing total cost by min(q,q')*(c' - c) . For 0-1 knapsack, where is a counterexample

Memory Choke on Branch And Bound Knapsack Implementation

本小妞迷上赌 提交于 2019-12-08 05:30:02
问题 I wrote this implementation of the branch and bound knapsack algorithm based on the pseudo-Java code from here. Unfortunately, it's memory choking on large instances of the problem, like this. Why is this? How can I make this implementation more memory efficient? The input on the file on the link is formatted this way: numberOfItems maxWeight profitOfItem1 weightOfItem1 . . . profitOfItemN weightOfItemN // http://books.google.com/books?id=DAorddWEgl0C&pg=PA233&source=gbs_toc_r&cad=4#v=onepage

01 Knapsack specialization

旧巷老猫 提交于 2019-12-08 02:51:35
问题 Excuse me if this has been answered already, but I don't have a deep knowledge of algorithms and don't always notice the subtleties between different specializations of the algorithms. I have (what I think is) a slight variant of the 01-Knapsack problem. I have a knapsack that has max weight W, and there are N items to choose from that have a weight w and value v. What I want to do is maximize the total value, V, without going over W. Classic Knapsack. Here's the twist : Of the items, I need

0-1 Knapsack with additional restriction (colored items)?

别来无恙 提交于 2019-12-08 02:41:35
问题 I'm working on this problem mostly out of curiosity in my downtime at work. Imagine the normal 0-1 Knapsack problem, except all the items are either yellow, red, blue, or green, and due to your OCD you must have exactly 2 items of each color in your knapsack. So instead of the normal items each item has 3 properties: Weight, Value, Color. Is this even still a knapsack problem, or is it better define in some other way? 回答1: I'll use nCk to represent "n choose k" for ease of typing. Since you

Knapsack prob, but allow over-filling

别来无恙 提交于 2019-12-08 01:57:14
问题 Lets say I have 5 items (name, size, value) as follows: ("ITEM01", 100, 10000) ("ITEM02", 24, 576) ("ITEM03", 24, 576) ("ITEM04", 51, 2500) ("ITEM05", 155, 25) and I have to get the closest match to a total size of 150 (each item can only be added once). This is very similar to the knapsack problem, but not quite since in this case my preferable solution would be ITEM01 , ITEM04 giving a total size of 151 (the knapsack problem would stop me going over size = 150 and hence give ITEM01 , ITEM02

Knapsack with “at least X value” constraint

你。 提交于 2019-12-07 14:19:03
问题 How would you go about solving this variation of Knapsack? You have n objects (x1,...xn), each with cost ci and value vi (1<=i<=n) and an additional constraint X, which is a lower bound on the value of the items selected. Find a subset of x1,...,xn that minimizes the cost of the items with a value of at least X. I am trying to solve this through Dynamic Programming, and what I thought of was to modify the usual table used into K[n,c,X] where X would be the minimum value I need to reach, but

Are these 2 knapsack algorithms the same? (Do they always output the same thing)

亡梦爱人 提交于 2019-12-07 02:49:25
问题 In my code, assuming C is the capacity, N is the amount of items, w[j] is the weight of item j, and v[j] is the value of item j, does it do the same thing as the 0-1 knapsack algorithm? I've been trying my code on some data sets, and it seems to be the case. The reason I'm wondering this is because the 0-1 knapsack algorithm we've been taught is 2-dimensional, whereas this is 1-dimensional: for (int j = 0; j < N; j++) { if (C-w[j] < 0) continue; for (int i = C-w[j]; i >= 0; --i) { //loop

1/0 Knapsack Variation with Weighted Edges

我只是一个虾纸丫 提交于 2019-12-06 20:43:31
I'm currently investigating a routing problem (finding a subset of places [each with a certain score] I want to visit while not exceeding a maximum travel time) and came up with a variation of the 1/0 knapsack problem that seems to solve my original problem. According to Wikipedia the 1/0 knapsack is described as: Given a set of items, each with a mass and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. So for each item there is a fixed weight (mass) that can