Refactored faulty solution into working solution

Solution now uses a bottoms-up dynamic programming approach. No brute
force needed.