#include <stdio.h>
using namespace std;
int n, r;
int check[20];
void DFS(int s, int L){
if(L==r){
for(int j=0; j<L; j++){
printf("%d ", check[j]);
}
printf("\n");
} else{
for(int i=s; i<n; i++){
check[L] = i;
DFS(i+1, L+1);
}
}
}
int main(){
freopen("input.txt", "rt", stdin);
scanf("%d %d", &n, &r);
DFS(0, 0);
return 0;
}
input
6 4
output
0 1 2 3
0 1 2 4
0 1 2 5
0 1 3 4
0 1 3 5
0 1 4 5
0 2 3 4
0 2 3 5
0 2 4 5
0 3 4 5
1 2 3 4
1 2 3 5
1 2 4 5
1 3 4 5
2 3 4 5
'알고리즘 > it 취업을 위한 알고리즘 문제풀이' 카테고리의 다른 글
87. 섬나라 아일랜드(BFS) (0) | 2021.06.17 |
---|---|
86. 피자 배달 거리(삼성 SW역량평가 기출문제 : DFS활용) (0) | 2021.06.16 |
85. 수식만들기(삼성 SW역량평가 기출문제 : DFS활용) (0) | 2021.06.15 |
84. 휴가(삼성 SW역량평가 기출문제 : DFS활용) (0) | 2021.06.15 |
83. 복면산 SEND+MORE=MONEY (0) | 2021.06.15 |