Advertisement
apl-mhd

coinChange

Mar 19th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. /*infinity supply*/
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. int coinChange(int coins[], int i, int make, int amount){
  9.  
  10.     if(i>=5){
  11.  
  12.         if(make == amount)
  13.             return  1;
  14.         else
  15.  
  16.         return 0;
  17.  
  18.     }
  19.  
  20.     int a,b;
  21.  
  22.     if(coins[i]+make <= amount)
  23.          a = coinChange(coins,i,make+coins[i], amount);
  24.  
  25.      b = coinChange(coins,i+1,make, amount);
  26.  
  27.  
  28.  
  29.     return a||b;
  30.  
  31.  
  32. }
  33.  
  34.  
  35. int rtrn(){
  36.  
  37.     return  1 < 0;
  38. }
  39.  
  40. int main() {
  41.  
  42.  
  43.    // cout<<rtrn();
  44.  
  45.     int coins[] = {5,5,5};
  46.  
  47.     cout<<coinChange(coins,0,0,10);
  48.  
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement