2025-07-23 00:02:58 +09:00

30 lines
573 B
C

#include <stdio.h>
#include <stdlib.h>
void dfs(int N, int M, int now, int* result, int ResLen){
if(ResLen == M) {
for(int i=0; i<M; i++) {
printf("%d ",result[i]);
}
printf("\n");
return;
}
for(int next = now; next<=N; next++){
result[ResLen] = next;
ResLen++;
dfs(N, M, next+1, result, ResLen);
ResLen--;
}
};
int main() {
int N, M;
scanf("%d %d", &N, &M);
int* result = (int*)malloc(sizeof(int)*M);
dfs(N, M, 1, result, 0);
free(result);
return 0;
}