Advertisement
apl-mhd

limited supply of coin

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