Start thinking about knapsack

Very difficult problem to solve, but many pre-existing solutions
This commit is contained in:
Blizzard Finnegan 2025-01-11 20:00:23 -05:00
parent b92478b09c
commit 6efd0ba5d8
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
2 changed files with 23 additions and 0 deletions

View file

@ -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
* */
}

View file

@ -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