티스토리 뷰

코딩/자바 백준

백준 6603 로또 (JAVA)

박상어 2021. 8. 22. 22:09
728x90

https://www.acmicpc.net/problem/6603

 

6603번: 로또

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로

www.acmicpc.net

 

 

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
46
47
48
49
50
import java.util.*;
 
public class Main {
    final static int MAX = 6;
    static int arr[];
    static int list[];
    static int K = -1;
    static StringBuilder sb = new StringBuilder();
 
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            K = sc.nextInt();
 
            if (K == 0) {
                break;
            }
 
            arr = new int[K];
            list = new int[MAX];
 
            for (int i = 0; i < K; i++) {
                arr[i] = sc.nextInt();
            }
 
            dfs(00);
 
            System.out.println(sb);
 
            sb = new StringBuilder();
        }
        sc.close();
    }
 
    private static void dfs(int idx1, int depth) {
        if (MAX == depth) {
 
            for (int i = 0; i < MAX; i++) {
                sb.append(list[i] + " ");
            }
            sb.append("\n");
            return;
        }
 
        for (int i = idx1; i < K; i++) {
            list[depth] = arr[i];
            dfs(i + 1, depth + 1);
        }
    }
}
cs

 

댓글