Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로그래머스 옹알이 java
- 프로그래머스 숫자의 표현 java
- java 반올림
- 백준 17425
- 자바
- java
- Codility
- Math.floor()
- 백준 11723
- 백준 14391
- 백준 16935
- Math.ceil()
- java 내림
- time complexity
- java 올림
- 알고리즘
- sort
- 0으로 채우기
- 네트워크
- 프로그래머스 네트워크 java
- 백준 18290
- mysql
- 프로그래머스 연속된 수의 합 java
- Arrays
- Algorithm
- 프로그래머스 도둑질 java
- 코딩테스트
- 백준 15661
- 백준 16927
- 백준 4375
Archives
- Today
- Total
취미처럼
[백준] 6603번 로또 본문
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;
}
}
}
}
'Algorithm > 백준' 카테고리의 다른 글
[백준] 1182번 부분수열의 합 (0) | 2021.03.04 |
---|---|
[백준] 11723번 집합 (0) | 2021.03.04 |
[백준] 10971번 외판원 순회 2 (0) | 2021.03.04 |
[백준] 10819번 차이를 최대로 (0) | 2021.03.04 |
[백준] 10974번 모든 순열 (0) | 2021.03.04 |
Comments