Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int n;
- int a[100];
- bool used[100]={false};
- void show(){
- for(int i=1;i<=n;i++){
- cout<<a[i];
- }
- }
- void backtracking(int pos){
- if(pos==n+1){
- show();
- cout<<endl;
- return ;
- }
- else{
- for(int i=1;i<=n;i++){
- if (used[i]==false){
- used[i]=true;
- a[pos]=i;
- backtracking(pos+1);
- used[i]=false;
- }
- }
- }
- }
- int main(){
- cin>>n;
- backtracking(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment