Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- ofstream fout("iesire.txt");
- const int max_n = 1e7;
- int st[max_n],n;
- void print(){
- for(int i=1;i<=n;++i)
- fout<<st[i]<<" ";
- fout<<endl;
- }
- int valid(int k){
- for(int i=1;i<k;++i)
- if(st[i]==st[k])
- return 0;
- return 1;
- }
- void bk(int k){
- if(k==n+1)
- print();
- else{
- for(int i=1;i<=n;++i){
- st[k]=i;
- if(valid(k))
- bk(k+1);
- }
- }
- }
- int main(){
- cin>>n;
- bk(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement