Advertisement
Wooph

Siruri

Feb 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7. ifstream fin("siruri.in");
  8. ofstream fout("siruri.out");
  9.  
  10. int st[10], n, m, v[100];
  11. int valid(int niv)
  12. {
  13.     int i;
  14.     for(i=1; i<=niv; i++){
  15.         if(st[i+1]-st[i]>2 && i<niv) return 0;
  16.         for(int j=i+1;j<=niv;j++)
  17.         {
  18.             if(st[i]>=st[j]) return 0;
  19.         }
  20.     }
  21.     return 1;
  22. }
  23. void afisare_stiva()
  24. {
  25.     int i;
  26.     for(i=1; i<=n; i++)
  27.         fout<<st[i]<<" ";
  28.     fout<<endl;
  29. }
  30. void back(int nivel)
  31. {
  32.     if (nivel>n) afisare_stiva();
  33.     else
  34.     {
  35.         for(int i=1; i<=m; i++)
  36.         {
  37.             st[nivel]=i;
  38.             if(valid(nivel)) back(nivel+1);
  39.         }
  40.     }
  41. }
  42.  
  43. int main()
  44. {
  45.     fin>>m;
  46.     fin>>n;
  47.     back(1);
  48.     fin.close();
  49.     fout.close();
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement