Domanda

Example:

Given 20$, I want to count WAYS to exchange 20$ with coins = { 5$,10$, 15$} The order of coins doesn’t matter.

solution here

The solution says : total num of ways = using coin + not use the coin : total_ways = count( S, m - 1, n ) + count( S, m, n-S[m-1] )

In form of tree: tree

È stato utile?

Soluzione

The solution says : total num of ways = using coin + not use the coin : total_ways = count( S, m - 1, n ) + count( S, m, n-S[m-1] )

I think you've misunderstood the solution statement a bit.

What it says exactly is:

1) Optimal Substructure
To count total number solutions, we can divide all set solutions in two sets.
1) Solutions that do not contain mth coin (or Sm).
2) Solutions that contain at least one Sm.

This is a way of subdividing the problem into two smaller versions of the same problem.

The number of ways it can be done without using the coin just the same problem with the same goal total and the smaller set of coins.

But the number of ways of it can be done with at least one of this coin is the same problem with the goal total reduced by the size of the coin, but with the same set of allowed coins.

In this second set, the same coin is indeed allowed to be used again.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top