https://www.acmicpc.net/problem/15652
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
static int n, m;
static int[] comb;
static StringBuilder sb = new StringBuilder();
static public void combination(int L, int start) {
if (L == m) {
for (int i : comb)
sb.append(i + " ");
sb.append("\n");
}
else {
for (int i = start; i <= n; i++) {
comb[L] = i;
combination(L+1, i);
}
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
comb = new int[m];
combination(0, 1);
System.out.println(sb);
}
}
조합과 중복조합의 차이는 재귀 시작 지점의 차이다. 조합은 중복을 허용하지 않기 때문에
combination(L+1, i+1)
을 호출하지만, 중복 조합은combination(L+1, i)
을 호출한다.