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.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/dynamic-programming/probability-dp/toss-strange-coins-implementation
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████████████████████████