SHARE
TWEET

Untitled

a guest Mar 21st, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int x[11],n;
  5.  ifstream fin("permutari1.in");
  6. ofstream fout("permutari1.out");
  7. void Retsol()
  8. {
  9.     int i;
  10.     for(i=1;i<=n;i++) fout<<x[i]<<" ";
  11.     fout<<endl;
  12. }
  13. int Cont(int k)
  14. {
  15.     int i;
  16.     for(i=1;i<=k-1;i++)
  17.         if(x[k]==x[i]) return 0;
  18.     return 1;
  19. }
  20. void Back(int k)
  21. {
  22.  
  23.     int i;
  24.     if(k==n+1)Retsol();
  25.     else {for(i=n;i>=1;i--)
  26.     {   x[k]=i;
  27.         if(Cont(k)) Back(k+1);
  28.     }
  29.           x[k]=n+1;}
  30. }
  31. int main()
  32. {
  33.  
  34.     fin>>n;
  35.     Back(1);
  36.     return 0;
  37. }
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