Algorithm/백준
[백준] 6603번 로또
sirius
2021. 3. 4. 17:26
https://www.acmicpc.net/problem/6603
6603번: 로또
입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로
www.acmicpc.net
import java.util.*;
import java.io.*;
public class Main {
public static int n;
public static int arr[];
public static boolean[] visit;
// 로또 6개 케이스
public static int ans[] = new int[6];
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = 0;
while(true){
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
if(n == 0) {
break;
} else {
arr = new int[n];
visit = new boolean[n];
for(int i = 0 ; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
dfs(0, 0);
System.out.println("");
}
}
}
public static void dfs(int start, int depth) {
// 로또 6개 케이스
if(depth == 6) {
for(int val : ans) {
System.out.print(val + " ");
}
System.out.println("");
return;
}
for(int i = start; i < n; i++) {
if(!visit[i]) {
visit[i] = true;
ans[depth] = arr[i];
dfs(i + 1 , depth + 1);
visit[i] = false;
}
}
}
}