[algo2] Used caching to solve knapsack problem.