findMinCoins(
intarr[],
intn,
intN) {
8 // dp[i] = no of coins required to get a total of i 9std::vector<int>
dp(N + 1);
11 // 0 coins are needed for 0 sum 15 for(
inti = 1; i <= N; i++) {
16 // initialize minimum number of coins needed to infinity 21 for(
intc = 0; c < n; c++) {
230)
// check if coins doesn't become negative by including it 24res =
dp[i - arr[c]];
26 // if total can be reached by including current coin c, 27 // update minimum number of coins needed dp[i] 29 dp[i] = min(
dp[i], res + 1);
33 // The Minimum No of Coins Required for N = dp[N] 38 // No of Coins We Have 39 intarr[] = {1, 2, 3, 4};
40 intn =
sizeof(arr) /
sizeof(arr[0]);
42 // Total Change Required 45cout <<
"Minimum Number of Coins Required "<< findMinCoins(arr, n, N)
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4