Knapsack Problem Dynamic Method Invocation