SHARE
TWEET

coin change

a guest Sep 19th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int count( int S[], int m, int n )
  4. {
  5.     int i, j, x, y;
  6.     int table[n + 1][m];
  7.     for (i = 0; i < m; i++)
  8.         table[0][i] = 1;
  9.     for (i = 1; i < n + 1; i++)
  10.     {
  11.         for (j = 0; j < m; j++)
  12.         {
  13.             x = (i-S[j] >= 0) ? table[i - S[j]][j] : 0;
  14.             y = (j >= 1) ? table[i][j - 1] : 0;
  15.             table[i][j] = x + y;
  16.         }
  17.     }
  18.     return table[n][m - 1];
  19. }
  20. int main()
  21. {
  22.     int arr[] = {2, 3};
  23.     int m = sizeof(arr)/sizeof(arr[0]);
  24.     int n = 6;
  25.     cout << count(arr, m, n);
  26.     return 0;
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top