This is one of the problems from Perking Online Judge with hints,discussion and complete solution code.
Problem Link -http://poj.org/problem?id=3624
Problem Description -
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.
Hints-
If you want to go ahead and solve this problem,great,here are a few things to keep in mind .
1.This is a dynamic programming problem in the sense that if we know that with a given weight W ,we can have a maximum desirability rating M then we can deduce the result from this point.
2.Brute force approach will not work given the time constraints.
3.This is basically a variation of the 0-1 Knapsack problem but there is a difference.Each object can only be selected at most once.
Read full article from POJ 3624-Charm Bracelet | Algorithms For Interviews And Competitive Programming
No comments:
Post a Comment