You are viewing a single comment's thread. Return to all comments →
JAVA SOLUTION
long[][] dp = new long[c.size()+1][n+1]; int m = c.size(); for(int j=0;j<=n;j++){ dp[0][j] = 0; } for(int i=0;i<=m;i++){ dp[i][0] = 1; } for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(c.get(i-1).intValue()>j){ dp[i][j] = dp[i-1][j]; } else{ dp[i][j] = dp[i-1][j] + dp[i][j-c.get(i-1).intValue()]; } } } return dp[m][n]; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Coin Change Problem
You are viewing a single comment's thread. Return to all comments →
JAVA SOLUTION