Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created March 22, 2014 21:55
Show Gist options
  • Save sreeprasad/9714992 to your computer and use it in GitHub Desktop.
Save sreeprasad/9714992 to your computer and use it in GitHub Desktop.
public static int coins(int []deno, int amount){
int dp[] = new int[amount+1];
dp[0]=0;
for(int j=1;j<=amount;j++){
dp[j]=Integer.MAX_VALUE;
for(int i=0;i<deno.length;i++){
if(deno[i]<=j && (1+dp[j-deno[i]] < dp[j]) )
dp[j]=1+dp[j-deno[i]];
}
}
showdp(dp);
return dp[amount];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment