forked from lshtar13/PS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15649.cc
37 lines (31 loc) · 768 Bytes
/
15649.cc
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
#include <bits/stdc++.h>
using namespace std;
void form(vector<int> &remain, vector<int> &result, int length)
{
if (result.size() == length)
{
for (auto &x : result)
printf("%d ", x);
printf("\n");
}
else
for (int i = 0, l = remain.size(); i < l; ++i)
{
int num = remain[i];
result.push_back(num);
remain.erase(remain.begin() + i);
form(remain, result, length);
remain.insert(remain.begin() + i, num);
result.pop_back();
}
}
int main(void)
{
int n, m;
scanf("%d %d", &n, &m);
vector<int> remain, result;
for (int i = 1; i <= n; ++i)
remain.push_back(i);
form(remain, result, m);
return 0;
}