top | item 28344908

(no title)

mvanaltvorst | 4 years ago

Yes, this would work. Hard to reason about LP solvers in complexity notation, but would probably be pretty quick.

You could also construct a graph, where every price is a node. Start at 0.00, and do a BFS until you find the desired price. Worst case scenario O(n) where n is the desired price. Could be optimised by using a path finding algorithm like A*, its heuristic would make it try a greedy algorithm at first and then do a more complex solve at the end.

Another possibility is by memoization (dynamic programming). Strictly worse than the graph algorithm in complexity terms, but in practice your computer is very good at working sequentially on a very big array of booleans.

Really many different approaches to solve this problem. In this specific case greedy worked as well.

discuss

order

No comments yet.