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