Advertisement
apl-mhd

coin change tushar roy infinity supply my implemention

Mar 26th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <climits>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <stack>
  7. #include <queue>
  8. #include <cmath>
  9. using namespace std;
  10.  
  11.  
  12. int main() {
  13.  
  14.  
  15. int coins [] = {0,2,3,4,7};
  16.  
  17.  
  18.     int max =999;
  19.  
  20.     int M[5][8];
  21.  
  22.     for(int i=0; i<=4; i++){
  23.         for(int j=0; j<=7; j++){
  24.  
  25.  
  26.             if(i==0 || j==0) {
  27.  
  28.                 M[i][j] = max;
  29.                 //break;
  30.             }
  31.             else
  32.  
  33.             if(j<coins[i]){
  34.  
  35.                 M[i][j]= M[i-1][j];
  36.  
  37.                 //cout<<"aa";
  38.             }
  39.             else if(j-coins[i] == 0)
  40.                 M[i][j] = 1;
  41.  
  42.             else{
  43.  
  44.                 M[i][j] = min(M[i-1][j], 1+M[i][j-coins[i]]);
  45.             }
  46.         }
  47.  
  48.     }
  49.  
  50.     for(int i=0; i<=4; i++){
  51.         for(int j=0; j<=7; j++) {
  52.  
  53.             cout<<M[i][j]<<" ";
  54.  
  55.         }
  56.  
  57.         cout<<endl;
  58.     }
  59.  
  60.             cout<<"end";
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement