-
Notifications
You must be signed in to change notification settings - Fork 2
/
15654_josueyeon.cpp
65 lines (49 loc) · 1.14 KB
/
15654_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
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <algorithm>
#include <vector>
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++)
{
int temp;
cin>>temp;
res.push_back(temp);
}
sort(res.begin(), res.end());
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());
vector<vector<int>> r;
do
{
vector<int> rest;
for(int i = 0;i < comb.size();i++)
{
if (comb[i] == 1)
rest.push_back(res[i]);
}
do
{
r.push_back(rest);
} while(next_permutation(rest.begin(), rest.end()));
} while(next_permutation(comb.begin(), comb.end()));
sort(r.begin(), r.end());
for(int i = 0;i < r.size();i++)
{
for(int j = 0;j < r[i].size();j++)
{
cout<<r[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}