Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool exist(int x,vector<int> v){
- for(int i=0;i<v.size();i++) if(v[i]==x) return true;
- return false;
- }
- void fun(int len, int n, vector<int> v){
- if(n==0){
- for(int i=0;i<v.size();i++){
- cout<<v[i]<<" ";
- }
- cout<<endl;
- return;
- }
- for(int i=1;i<=len;i++){
- if(exist(i,v)) continue;
- vector<int>tmp=v;
- tmp.push_back(i);
- fun(len, n-1,tmp);
- }
- }
- int main()
- {
- int n;
- cin>>n;
- vector<int> v;
- fun(n,n,v);
- }
Add Comment
Please, Sign In to add comment