백준 - 6603 - 로또
2021. 3. 23. 14:53ㆍAlgorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import java.util.Scanner;
/**
* 백준 - 6603
*/
public class 로또 {
private static String[] inputs;
private static boolean[] isVisit;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
inputs = sc.nextLine().split(" ");
isVisit = new boolean[inputs.length];
if(inputs[0].equals("0")) {
return;
}
printCombination(6, 1);
System.out.println();
}
}
private static void printCombination(int depth, int start) {
//종료
if(depth == 0) {
StringBuilder sb = new StringBuilder();
for(int i=1; i<isVisit.length; i++) {
if(isVisit[i]) {
sb.append(inputs[i]+ " ");
}
}
System.out.println(sb.toString().trim());
}
//프로세스
for(int i=start; i<inputs.length; i++) {
isVisit[i] = true;
printCombination(depth-1, i+1);
isVisit[i] = false;
}
}
}
|
cs |
알고리즘
조합(Combination)
기본적인 M개 중에서 N개로 만들수 있는 조합을 구하는 문제
'Algorithm' 카테고리의 다른 글
백준 - 1987 - 알파벳 (0) | 2021.03.25 |
---|---|
백준 - 1759 - 암호 만들기 (0) | 2021.03.23 |
프로그래머스 - 힙 - 이중우선순위큐 (0) | 2021.03.23 |
프로그래머스 - 힙 - 디스크 컨트롤러 (0) | 2021.03.22 |
프로그래머스 - 힙 - 더 맵게 (0) | 2021.03.21 |