Knapsack problem is a typical dynamic programming example see http://en.wikipedia.org/wiki/Dynamic_programming

It is explained in more detail at http://en.wikipedia.org/wiki/Knapsack_problem

So we have a big list of items of various sizes to fit in a knapsack of a fixed size. The idea is that we calculate the values for all knapsack sizes, so that when we have any spaces left, we use our knowledge of previous solutions to fill things in.

For example, let's say the knapsack size is 10. We'll start the most items we can fit in at sizes, 1, 2, 3 ..., 10. By the time we get to size 7 (for example), we already know the optimal items to put in to fill in a size 3 problem and we can just do that. (A very rough description, but enough to get the general idea).

As Venabili says, doing homework is against the rules, so perhaps if you post some example code or have a stab at it, we can help you out some more.

I'm guessing the MF (memory function) is just memoisation (or at least I assume it is, maybe you have some other complicated technique for the knapsack problem). Memoisation is just recalling previous results, without repeating calculations, see http://en.wikipedia.org/wiki/Memoization

It is explained in more detail at http://en.wikipedia.org/wi

So we have a big list of items of various sizes to fit in a knapsack of a fixed size. The idea is that we calculate the values for all knapsack sizes, so that when we have any spaces left, we use our knowledge of previous solutions to fill things in.

For example, let's say the knapsack size is 10. We'll start the most items we can fit in at sizes, 1, 2, 3 ..., 10. By the time we get to size 7 (for example), we already know the optimal items to put in to fill in a size 3 problem and we can just do that. (A very rough description, but enough to get the general idea).

As Venabili says, doing homework is against the rules, so perhaps if you post some example code or have a stab at it, we can help you out some more.

I'm guessing the MF (memory function) is just memoisation (or at least I assume it is, maybe you have some other complicated technique for the knapsack problem). Memoisation is just recalling previous results, without repeating calculations, see http://en.wikipedia.org/wi