728x90
300x250
중복조합 문제.
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static int N,M;
public static StringBuilder sb = new StringBuilder();
public static int[] ans;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
StringTokenizer st = new StringTokenizer(s);
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
ans = new int[M];
dfs(1,0);
System.out.println(sb);
}
public static void dfs(int num, int idx) {
//종료조건
//idx가 뽑을 갯수가 됐냐?
if(idx==M) {
for (int i = 0; i < ans.length; i++) {
sb.append(ans[i]+" ");
}
sb.append("\n");
return;
}
for (int i = num; i <= N; i++) {
ans[idx]= i;
dfs(i,idx+1);
}
}
}
728x90
'알고리즘 > 조합 & 순열' 카테고리의 다른 글
백준 15655번: N과 M (6) (0) | 2020.03.04 |
---|---|
백준 15654번: N과 M (5) (0) | 2020.03.04 |
백준 15651번: N과 M (3) (0) | 2020.03.03 |
백준 15650번: N과 M (2) (0) | 2020.03.03 |
백준 15649번: N과 M (1) (0) | 2020.03.03 |