class Main {
static int m, n;
public void DFS (int level, int start, int []combi) {
if( level == m) {
for ( int x : combi)
System.out.print(x+ " ");
System.out.println();
} else {
for( int i=start; i <= n ; i++) {
combi[level] = i;
DFS(level+1, i +1, combi );
}
}
}
public static void main(String args[]) throws Exception {
Main M = new Main();
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
int []combi = new int[m];
M.DFS(0, 1, combi);
}
}
ex)
input
4 2
output
1 2
1 3
1 4
2 3
2 4
3 4
'PS > inflearn java coding' 카테고리의 다른 글
미로 최단거리 구하기 (BFS) (0) | 2022.04.13 |
---|---|
순열, 조합 연습 (0) | 2022.04.13 |
수열추측 (조합) (0) | 2022.04.13 |
간단한 조합 설명. (0) | 2022.04.13 |
순열 출력 (0) | 2022.04.12 |