-
Notifications
You must be signed in to change notification settings - Fork 0
/
15650.cpp
44 lines (37 loc) · 883 Bytes
/
15650.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
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
void solve(int start,int n,int m,bool selected[9],vector<int> &v){
int size = v.size();
if(size == m){
for(int i=0;i<size;i++){
printf("%d ",v[i]);
}
printf("\n");
}
for(int i=start;i<=n;i++){
if(selected[i] == false){
selected[i] = true;
v.push_back(i);
solve(i,n,m,selected,v);
v.pop_back();
selected[i] = false;
}
}
}
int main(){
int n,m;
bool selected[9];
scanf("%d %d",&n,&m);
memset(selected,false,sizeof(bool)*9);
for(int i=1;i<=n;i++){
vector<int> numbers;
selected[i] = true;
numbers.push_back(i);
solve(i,n,m,selected,numbers);
selected[i] = false;
numbers.pop_back();
}
return 0;
}