Full table: space. But each row only depends on the previous row. Use two arrays: and . Swap after each coin. Space: . Or use single array with reverse iteration: , iterating from down to . Time: , Space: . The pattern is identical to 0/1 Knapsack space reduction. Space reduction works because each row only depends on the previous row. You can use two arrays or reverse iteration.
Dynamic Programming21 sections · 916 units
Open in CourseToss Strange Coins - Implementation
Space optimization