-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcnm.cpp
More file actions
45 lines (39 loc) · 801 Bytes
/
Copy pathcnm.cpp
File metadata and controls
45 lines (39 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void cmn(vector<vector<int>>&res,vector<int> &nums,int start, int length)
{
if(start==nums.size()||length==0)
{
res.push_back(vector<int> (nums.begin()+start,);
return;
}
for(int i=start;i<nums.size();++i)
{
swap(nums[start],nums[i]);
cmn(res,nums,start+1,length-1);
swap(nums[start],nums[i]);
}
}
int main()
{
int N,M;
cin>>N>>M;
vector<int> P;
int i;
for(int j=0;j<N;j++)
{
cin>>i;
P.push_back(i);
}
vector<vector<int>> res;
cmn(res,P,0,M);
for(int i=0;i<res.size();i++)
{
for(int j=0;j<res[0].size();j++)
cout<<res[i][j]<<" ";
cout<<endl;
}
return 0;
}