-
Notifications
You must be signed in to change notification settings - Fork 2
/
15650_josueyeon.cpp
53 lines (41 loc) · 977 Bytes
/
15650_josueyeon.cpp
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
46
47
48
49
50
51
52
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin>>N>>M;
vector<int> res;
vector<int> comb;
for(int i = 1;i <= N;i++)
res.push_back(i);
for(int i = 0;i < M;i++)
comb.push_back(1);
for(int i = 0;i < N - M;i++)
comb.push_back(0);
sort(comb.begin(), comb.end());
stack<vector<int>> ans;
do
{
vector<int> rest;
for(int i = 0;i < comb.size();i++)
{
if (comb[i] == 1)
rest.push_back(res[i]);
}
ans.push(rest);
} while(next_permutation(comb.begin(), comb.end()));
while(!ans.empty())
{
vector<int> temp = ans.top();
for(int i = 0;i < temp.size();i++)
cout<<temp[i]<<" ";
cout<<"\n";
ans.pop();
}
return 0;
}