Advertisement
aimon1337

Untitled

Feb 26th, 2020
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. using namespace std;
  4. ofstream fout("iesire.txt");
  5. const int max_n = 1e7;
  6. int st[max_n],n;
  7. void print(){
  8.     for(int i=1;i<=n;++i)
  9.         fout<<st[i]<<" ";
  10.     fout<<endl;
  11. }
  12. int valid(int k){
  13.     for(int i=1;i<k;++i)
  14.         if(st[i]==st[k])
  15.             return 0;
  16.     return 1;
  17. }
  18. void bk(int k){
  19.     if(k==n+1)
  20.         print();
  21.     else{
  22.         for(int i=1;i<=n;++i){
  23.             st[k]=i;
  24.             if(valid(k))
  25.                 bk(k+1);
  26.         }
  27.     }
  28. }
  29. int main(){
  30.     cin>>n;
  31.     bk(1);
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement