20250722 baekjoon
This commit is contained in:
parent
c4ecc66191
commit
fdcf787662
30
code_study/Baekjoon/c/15650.c
Normal file
30
code_study/Baekjoon/c/15650.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
12
code_study/Baekjoon/python/15650.py
Normal file
12
code_study/Baekjoon/python/15650.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
def dfs(now, N, M, result) :
|
||||||
|
if len(result) == M :
|
||||||
|
print(*result)
|
||||||
|
return
|
||||||
|
|
||||||
|
for next in range(now, N+1) :
|
||||||
|
result.append(next)
|
||||||
|
dfs(next+1,N,M,result)
|
||||||
|
result.pop()
|
||||||
|
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
dfs(1,N,M,[])
|
||||||
Loading…
x
Reference in New Issue
Block a user