Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Since you asked for mathematical background...

In general, the Change-making problem is a knapsack problem, which is NP-hard. However, for sane sets of currency denominations, a simple greedy algorithm works for sane sets of currency denominations, a simple greedy algorithm works.

For your set of denominations, { 1000, 500, 300, 100, 50 }, the greedy algorithm applies. (There is, however, an amount with two optimal solutions: 600 = 500 +たす 100 = 300 +たす 300.) Therefore, your greedy algorithm and @MartVandeVen's simplified implementation of it will work.

Since you asked for mathematical background...

In general, the Change-making problem is a knapsack problem, which is NP-hard. However, for sane sets of currency denominations, a simple greedy algorithm works.

For your set of denominations, { 1000, 500, 300, 100, 50 }, the greedy algorithm applies. (There is, however, an amount with two optimal solutions: 600 = 500 +たす 100 = 300 +たす 300.) Therefore, your greedy algorithm and @MartVandeVen's simplified implementation of it will work.

Since you asked for mathematical background...

In general, the Change-making problem is a knapsack problem, which is NP-hard. However, for sane sets of currency denominations, a simple greedy algorithm works.

For your set of denominations, { 1000, 500, 300, 100, 50 }, the greedy algorithm applies. (There is, however, an amount with two optimal solutions: 600 = 500 +たす 100 = 300 +たす 300.) Therefore, your greedy algorithm and @MartVandeVen's simplified implementation of it will work.

Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

Since you asked for mathematical background...

In general, the Change-making problem is a knapsack problem, which is NP-hard. However, for sane sets of currency denominations, a simple greedy algorithm works.

For your set of denominations, { 1000, 500, 300, 100, 50 }, the greedy algorithm applies. (There is, however, an amount with two optimal solutions: 600 = 500 +たす 100 = 300 +たす 300.) Therefore, your greedy algorithm and @MartVandeVen's simplified implementation of it will work.

default

AltStyle によって変換されたページ (->オリジナル) /