-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15657.cpp
More file actions
38 lines (32 loc) · 671 Bytes
/
Copy path15657.cpp
File metadata and controls
38 lines (32 loc) · 671 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
#include <iostream>
#include <vector>
#include <algorithm>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int N,M;
int nums[9];
int res[9];
void backtracking(int n,int depth,int pre){
if(pre<=n){
if(depth==M){
for(int i=1;i<=M;i++) cout<<res[i]<<' ';
cout<<'\n';
}else{
for(int i=1;i<=N;i++){
res[depth+1]=nums[i];
backtracking(nums[i],depth+1,res[depth]);
}
}
}
}
int main()
{
io;
cin>>N>>M;
for(int i=1;i<=N;i++){
cin>>nums[i];
}
sort(&nums[1],&nums[1]+N);
backtracking(0,0,0);
return 0;
}