링크 : https://www.acmicpc.net/problem/15652
#include <iostream>
using namespace std;
#define MAX 9
int N, M;
int arr[MAX];
bool visited[MAX];
void dfs(int s, int cnt){
if(cnt >= M){
for(int i = 0; i < M; i++)
cout << arr[i] << " ";
cout << '\n';
return;
}
else{
for(int i = s; i <= N; i ++){
visited[i] = true;
arr[cnt] = i;
dfs(i, cnt+1);
visited[i] = false;
}
}
}
int main(){
cin >> N >> M;
dfs(1, 0);
}