TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Knapsack problem

31 pointsby groundCodeabout 12 years ago

9 comments

hackerboosabout 12 years ago
I studied if for my university dissertation.<p>It's easy to think of practical applications, example - I have a folder of videos/mp3s etc and I want to fit them on a few DVD-Rs. This algorithm can calculate the most efficient way of getting the most data on the disk without splitting files.
评论 #5596458 未加载
评论 #5596768 未加载
评论 #5596209 未加载
bkanberabout 12 years ago
I wrote a tutorial on solving the knapsack problem with genetic algorithms in javascript a while back:<p><a href="http://burakkanber.com/blog/machine-learning-genetic-algorithms-in-javascript-part-2/" rel="nofollow">http://burakkanber.com/blog/machine-learning-genetic-algorit...</a><p>There are better ways to solve this problem, of course, but the primary goal was to talk about GAs, not to solve the knapsack problem in the most efficient manner.
itomatikabout 12 years ago
Can somebody tell me if the following problem is solvable using knapsack (so far I've been only able to come up with bruteforce solution with some optimizations): We have different product types and for each product know it's amount. Let's say we have 20 different product types. For each type we know how much we've got (i.e. 10k of product type 1, 15k of product type 2, etc.) Now we want to put those products into different bags. Each bag must have 5 products. A particular combination of products inside of the bag is considered a "bag type". If we choose a particular "bag type" we must to have at least 7,500 units of such bag type. For each bag type we have a certain cost function.<p>Now the problem is to find bags types and corresponding amounts such that total cost is maximized.
评论 #5596169 未加载
zuraabout 12 years ago
This is on of the mind opening problems. The whole dynamic programming is mind opening, I'd say.
ambiateabout 12 years ago
Drawing huge state trees for the branch and bound solution to this problem was heart breaking on 40 minute exams.
IgorPartolaabout 12 years ago
In the little example they give on the side, why not sort all items by value density, high to low, then fit items until the knapsack is full? Not so simple for multiple dimensions, but when does this not work in a single dimension case?
评论 #5596099 未加载
heroicabout 12 years ago
I and a colleague used Knapsack algorithm for a very interesting use case. You can find it here <a href="https://github.com/heroic/Rucksack" rel="nofollow">https://github.com/heroic/Rucksack</a>
chadhietalaabout 12 years ago
I had to do this for an interview... in clojure. <a href="https://github.com/chadhietala/smuggler" rel="nofollow">https://github.com/chadhietala/smuggler</a>
leeoniyaabout 12 years ago
combinatorics as the whole is quite interesting. i've done an implementation that arranges different fixed-dimension flooring panels into rooms of different sizes.
评论 #5596652 未加载