Created
September 23, 2017 22:20
-
-
Save jrziviani/80984957d9dbfb302b2a1e1996d89c72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long long make_change(vector<int> coins, int money) { | |
long int t[money + 1][coins.size() + 1]; | |
for (size_t i = 0; i <= money; i++) | |
t[i][0] = 0; | |
for (size_t i = i; i <= coins.size(); i++) | |
t[0][i] = 1; | |
for (size_t i = 1; i <= money; i++) { | |
for (size_t j = 1; j <= coins.size(); j++) { | |
if (coins[j - 1] <= i) { | |
t[i][j] = t[i - coins[j - 1]][j] + t[i][j - 1]; | |
} | |
else { | |
t[i][j] = t[i][j - 1]; | |
} | |
} | |
} | |
/* | |
cout << " coins " << endl; | |
cout << " +---+---+---+---+" << endl; | |
cout << " | 0 | 1 | 2 | 3 |" << endl; | |
cout << " +---+---+---+---+" << endl; | |
for (size_t i = 0; i <= money; i++) { | |
cout << i << " | "; | |
for (size_t j = 0; j <= coins.size(); j++) { | |
cout << t[i][j] << " | "; | |
} | |
cout << endl; | |
} | |
cout << " +---+---+---+---+" << endl; | |
*/ | |
return t[money][coins.size()]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment