Start thinking about knapsack
Very difficult problem to solve, but many pre-existing solutions
This commit is contained in:
parent
b92478b09c
commit
6efd0ba5d8
2 changed files with 23 additions and 0 deletions
|
@ -1 +1,22 @@
|
|||
#include "knapsack.h"
|
||||
|
||||
int maximum_value(unsigned int maximum_weight, item_t *items, size_t item_count){
|
||||
unsigned int current_capacity = 0;
|
||||
unsigned int current_value = 0;
|
||||
/* Account for bad pointer */
|
||||
if(items == NULL){ return 0; }
|
||||
|
||||
/*
|
||||
* Thought process:
|
||||
* We want max value. We should be checking both as many high value objects as possible
|
||||
* into the bag, as well as checking the most amount of small objects in the bag as possible.
|
||||
*
|
||||
* According to Wikipedia, the unbounded version problem is NP-complete; that is, it's
|
||||
* impossible to have a catch-all solution that always spits out the right answer.
|
||||
*
|
||||
* This specific variation seems to be the "0-1 knapsack" variant (essentially), which means
|
||||
* it's easier, but still not great.
|
||||
*
|
||||
* Several solutions exist online already
|
||||
* */
|
||||
}
|
||||
|
|
|
@ -6,4 +6,6 @@ typedef struct {
|
|||
unsigned int value;
|
||||
} item_t;
|
||||
|
||||
int maximum_value(unsigned int maximum_weight, item_t *items, size_t item_count);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue