SHARE
TWEET

ex5pag19clXI

a guest Sep 22nd, 2019 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int st[100];
  5. int n,v[100]={0,0,2,4,6,8};
  6.  
  7. void init(int k)
  8. {
  9.     st[k]=0;
  10. }
  11. int succesor(int k)
  12. {
  13.     if(st[k]<6)
  14.     {
  15.         st[k]=st[k]+1;
  16.         return 1;
  17.     }
  18.     else
  19.         return 0;
  20. }
  21. int valid(int k)
  22. {
  23.     for(int i=1;i<=k;i++)
  24.         if(st[k]>st[i])
  25.             return 0;
  26.     return 1;
  27. }
  28. int solutie(int k)
  29. {
  30.     return k==n;
  31.  
  32. }
  33.  void tipar(int k)
  34. {
  35.     if(v[st[1]]!=0)
  36.     {
  37.     for(int i=1;i<=n;i++)
  38.             cout<<v[st[i]]<<" ";
  39.     cout<<endl;
  40.     }
  41. }
  42. void bkt(int k)
  43. {
  44.     init(k);
  45.     while(succesor(k))
  46.         if(valid(k))
  47.             if(solutie(k))
  48.                 tipar(k);
  49.             else
  50.                 bkt(k+1);
  51. }
  52. int main()
  53. {
  54.     cout<<"n=";
  55.     cin>>n;
  56.     bkt(1);
  57.     return 0;
  58. }
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