Created
July 22, 2017 15:25
-
-
Save Sharma96/9796140c1b12f39aad2f216a3bb889bc to your computer and use it in GitHub Desktop.
This file contains 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
//consider dp[] to be a global array | |
int minCoins(int N, int M) | |
{ | |
if(dp[N] != -1) | |
return dp[N]; | |
if (N == 0) | |
return 0; | |
int res = INF; | |
for(int i=0;i<M;i++){ | |
if(coins[i]<=N){ | |
int sub_res = 1+minCoins(N-coins[i],M); | |
if (sub_res < res) | |
res = sub_res; | |
} | |
} | |
return dp[N] = res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment