diff --git a/LeetCode/8. Coin change problem: Maximum number of ways b/LeetCode/8. Coin change problem: Maximum number of ways new file mode 100644 index 0000000..64ee634 --- /dev/null +++ b/LeetCode/8. Coin change problem: Maximum number of ways @@ -0,0 +1,33 @@ +class Solution +{ + public: + + long long int count( int s[], int m, int n ) + { + long long int dp[n+1][m+1]; + for(int i=0;i<=n;i++) + { + for(int j=0;j<=m;j++) + { + if(i==0 or (i==0 and j==0)) + { + dp[i][j]=1; + } + else if(j==0) + { + dp[i][j]=0; + } + else if(s[j-1]<=i) + { + dp[i][j]=dp[i-s[j-1]][j]+dp[i][j-1]; + } + else + { + dp[i][j]=dp[i][j-1]; + } + } + } + return dp[n][m]; + //code here. + } +};